home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Information / Digests / CSMP Digest / volume 3 / csmp-digest-v3-066 < prev    next >
Encoding:
Text File  |  1994-12-08  |  162.2 KB  |  2,602 lines  |  [TEXT/R*ch]

  1. C.S.M.P. Digest             Mon, 07 Nov 94       Volume 3 : Issue 66
  2.  
  3. Today's Topics:
  4.  
  5.         #defines by the compiler (CodeWarrior)
  6.         Announcement: New Mac C++ Programming Book Available
  7.         Apple Guide:  Styled text FUBAR
  8.         Basic GWorlds and QuickDraw Newbie
  9.         CW & Code Resources -- poor?
  10.         Desktop Pictures
  11.         Drag-and-drop to cdev window?
  12.         Fastest way to fill memory with a given value?
  13.         Gestalt Selectors List 2.6
  14.         Global storage in code resources
  15.         How to execute MPW tools without MPW
  16.         MacTCP Completion Routines & Async Nofification
  17.         Memory Management within the Real World
  18.         NewGWorld returns null pointer
  19.         Pathnames? I don't think so...
  20.         Q: Creating Variable sized structures?
  21.         QuickTime + MIDI?
  22.         Software volume locking: HELP!
  23.         Some string routines for the PowerPC
  24.         Tech Notes on the World Wide Web, and History Is Made
  25.  
  26.  
  27.  
  28. The Comp.Sys.Mac.Programmer Digest is moderated by Francois Pottier
  29. (pottier@clipper.ens.fr).
  30.  
  31. The digest is a collection of article threads from the internet newsgroup
  32. comp.sys.mac.programmer.  It is designed for people who read c.s.m.p. semi-
  33. regularly and want an archive of the discussions.  If you don't know what a
  34. newsgroup is, you probably don't have access to it.  Ask your systems
  35. administrator(s) for details.  If you don't have access to news, you may
  36. still be able to post messages to the group by using a mail server like
  37. anon.penet.fi (mail help@anon.penet.fi for more information).
  38.  
  39. Each issue of the digest contains one or more sets of articles (called
  40. threads), with each set corresponding to a 'discussion' of a particular
  41. subject.  The articles are not edited; all articles included in this digest
  42. are in their original posted form (as received by our news server at
  43. nef.ens.fr).  Article threads are not added to the digest until the last
  44. article added to the thread is at least two weeks old (this is to ensure that
  45. the thread is dead before adding it to the digest).  Article threads that
  46. consist of only one message are generally not included in the digest.
  47.  
  48. The digest is officially distributed by two means, by email and ftp.
  49.  
  50. If you want to receive the digest by mail, send email to listserv@ens.fr
  51. with no subject and one of the following commands as body:
  52.     help                        Sends you a summary of commands
  53.     subscribe csmp-digest Your Name    Adds you to the mailing list
  54.     signoff csmp-digest            Removes you from the list
  55. Once you have subscribed, you will automatically receive each new
  56. issue as it is created.
  57.  
  58. The official ftp info is //ftp.dartmouth.edu/pub/csmp-digest.
  59. Questions related to the ftp site should be directed to
  60. scott.silver@dartmouth.edu. Currently no previous volumes of the CSMP
  61. digest are available there.
  62.  
  63. Also, the digests are available to WAIS users.  To search back issues
  64. with WAIS, use comp.sys.mac.programmer.src. With Mosaic, use
  65. http://www.wais.com/wais-dbs/comp.sys.mac.programmer.html.
  66.  
  67.  
  68. -------------------------------------------------------
  69.  
  70. >From zobkiw@datawatch.com (joe zobkiw)
  71. Subject: #defines by the compiler (CodeWarrior)
  72. Date: Mon, 17 Oct 1994 13:45:40 GMT
  73. Organization: Datawatch Corporation
  74.  
  75. I have been writing some Aladdin InstallerMaker extensions recently and
  76. have a nice little system that (using two projects and a "switch" in my
  77. main source file) allows me to compile the extension as an application for
  78. easy testing. Then, when I'm done, I can switch projects, switch the
  79. #define switch in my main source file, and compile it as the proper
  80. resource type.
  81.  
  82. My question is, since CodeWarrior doesn't have a nice little "Prefix" type
  83. per-project option like THINK C had, is there another way? It would be
  84. great if the compiler knew what TYPE it was compiling the code as and I
  85. could get at this information in my code. Something like:
  86.  
  87. #ifdef APPL               // APPL is the TYPE of the project
  88.   InitializeMacintoshManagers();
  89. #endif
  90.  
  91. #ifdef IBeg               // IBeg is the RESOURCE TYPE of the project
  92.    SysBeep(0);
  93. #endif
  94.  
  95. Is there another way to accomplish this? Any thoughts?
  96.  
  97. _______________________________________________________ ,,,
  98. Joe Zobkiw                         zobkiw@datawatch.com - -
  99. Senior Software Engineer          Datawatch Corporation  L
  100. ___________ Zeros and Ones will take us there __________ _
  101.  
  102. +++++++++++++++++++++++++++
  103.  
  104. >From mwron@aol.com (MW Ron)
  105. Date: 17 Oct 1994 12:22:03 -0400
  106. Organization: America Online, Inc. (1-800-827-6364)
  107.  
  108. In article <zobkiw-1710940845400001@zobkiw.datawatch.com>,
  109. zobkiw@datawatch.com (joe zobkiw) writes:
  110.  
  111. >>My question is, since CodeWarrior doesn't have a nice little "Prefix"
  112. type per-project option like THINK C had, is there another way? It would
  113. be great if the compiler knew what TYPE it was compiling the code as and I
  114. could get at this information in my code.
  115.  
  116.  
  117. The "Prefix File" option in the Languages Preferences lets you specify
  118. a file that gets automatically prepended to every file. Be default, it is
  119. set to the precompiled header for the Toolbox routines. However, you can
  120. specify your own file.
  121.  
  122. For example, you could specify a Prefix File of  MyPrefix.h, where the
  123. contents of MyPrefix.h was:
  124.  
  125. #include <MacHeaders68K>   // Included precompiled header
  126.             // Define Symbols
  127.  
  128. #ifdef APPL               // APPL is the TYPE of the project
  129.   InitializeMacintoshManagers();
  130. #endif
  131.  
  132. #ifdef IBeg               // IBeg is the RESOURCE TYPE of the project
  133.    SysBeep(0);
  134. #endif
  135.  
  136. Your Prefix File can contain any valid C statements.
  137.  
  138. Ron Liechty
  139. RonL@metrowerks.com
  140. Metrowerks Inc.
  141.  
  142.  
  143.  
  144. ---------------------------
  145.  
  146. >From danparks@aol.com (DanParks)
  147. Subject: Announcement: New Mac C++ Programming Book Available
  148. Date: 15 Oct 1994 16:56:04 -0400
  149. Organization: America Online, Inc. (1-800-827-6364)
  150.  
  151. //******************************************************
  152.    Apologies if this isn't the proper newsgroup for this message.
  153.    I posted it to comp.sys.mac.announce, but it was returned as
  154.          "not acceptable topic for this newsgroup" !!
  155. //******************************************************
  156.  
  157. To All:
  158.  
  159. There's a new Mac programming book now available - "Symantec C++:
  160. Object-Oriented Programming Fundamentals for the Macintosh" by Prima
  161. Publishing. It should be at your bookstore by the time you read this. 
  162.  
  163. "Symantec C++:  Object-Oriented Programming Fundamentals for the
  164. Macintosh"
  165. Dan Parks Sydow
  166. Prima Publishing
  167. ISBN:  1-55958-633-8
  168.  
  169. The book assumes the reader has a knowledge of a higher-level language -
  170. preferably the C language. It also assumes the reader has done at least a
  171. little programming on the Mac. No advanced-level programming skills are
  172. needed, and no previous knowledge of C++ is required.
  173.  
  174. Like my previous Prima book, "Think THINK C", this book comes bundled with
  175. a disk that contains ALL of the source code examples presented in the
  176. book. It also has a tutorial software program that covers the major topics
  177. from the book, from a little different perspective. That program is called
  178. Simulator C++. The purpose of the software is to "bring to life" the
  179. concepts in the book through the use of text, graphics, QuickTime movies,
  180. and on-screen questions and answers.
  181.  
  182. All examples in the book work with Symantec C++ version 6 or version 7.
  183. All examples run on either a 680x0 Mac or a Power Mac. There are a couple
  184. of dozen example programs - most of them short and covering just a single
  185. key topic. But there are also a couple of larger programs that incorporate
  186. many C++/object-oriented programming concepts. Earlier examples stress
  187. basic techniques, later examples stress programming C++ using Macintosh
  188. techniques - writing programs that make use of menus, dialogs, windows,
  189. resources, and graphics.
  190.  
  191. As always, please feel free to send email to me ( addresses shown below)
  192. with any comments/suggestions/kind words/complaints/questions.
  193.  
  194. *Note to CodeWarrior Owners*
  195. If you want to learn C++ programming for the Mac, this book MAY be for
  196. you. You'd have to be willing to skip one chapter of the book, and make
  197. minimal changes to the source code. You CodeWarrior owners shouldn't have
  198. too much trouble adapting the examples to your Metrowerks compiler. You'll
  199. need to create a new project, then add the included source code file to
  200. it. Most source code files need only one or two changes to compile with
  201. CodeWarrior. I'll be posting an errata sheet in this newsgroup next week
  202. for CodeWarrior users. It will detail the changes that need to be made.
  203.  
  204. Internet:  danparks@aol.com
  205. CompuServe:   73747,1401
  206. America Online:  DanParks
  207.  
  208.  
  209. Regards,
  210.  
  211. Dan
  212.  
  213.  
  214.  
  215. +++++++++++++++++++++++++++
  216.  
  217. >From zobkiw@datawatch.com (joe zobkiw)
  218. Date: Mon, 17 Oct 1994 13:38:50 GMT
  219. Organization: Datawatch Corporation
  220.  
  221. In article <37pfl4$t91@newsbf01.news.aol.com>, danparks@aol.com (DanParks)
  222. wrote:
  223.  
  224. > //******************************************************
  225. >    Apologies if this isn't the proper newsgroup for this message.
  226. >    I posted it to comp.sys.mac.announce, but it was returned as
  227. >          "not acceptable topic for this newsgroup" !!
  228. > //******************************************************
  229.  
  230. How could the Macintosh programmers newsgroup not be the right place for
  231. an announcement about a new book about Macintosh programming? :) 
  232.  
  233. This damn info-super-highway has everyone afraid of getting flamed for the
  234. littlest thing, much like most kids in the inner-city are afraid to go to
  235. school because they'll get shot. So what do they do? Skip school and not
  236. post.
  237.  
  238. Dan, it sounds like a good book. Thanks for the info.
  239.  
  240. _______________________________________________________ ,,,
  241. Joe Zobkiw                         zobkiw@datawatch.com - -
  242. Senior Software Engineer          Datawatch Corporation  L
  243. ___________ Zeros and Ones will take us there __________ _
  244.  
  245. ---------------------------
  246.  
  247. >From cwiltgen@mcs.com (Charles Wiltgen)
  248. Subject: Apple Guide:  Styled text FUBAR
  249. Date: Sat, 22 Oct 1994 18:09:26 -0500
  250. Organization: Muso Communications
  251.  
  252. It's a major pain to use styled text in Apple Guide.  Basically, I can't
  253. make any hypertext links stand out because Apple didn't think of including
  254. an "embolden" tag in the dang compiler.
  255.  
  256. What is everyone using to create Apple Guide files with?  SimpleText is
  257. out of the question.  I'd like to use WriteNow, but the GuideMaker crashes
  258. when it tries to read it.
  259.  
  260. Anyone have a solution?
  261.  
  262. -- 
  263. Charles Wiltgen    "Love is a snowmobile racing across the tundra and
  264. cwiltgen@mcs.com    then suddenly it flips over, pinning you underneath.
  265. (INTP)              At night, the ice weasels come." - Nietzsche (Groening)
  266. The Apocalypso!     http://www.mcs.net/~cwiltgen
  267.  
  268. +++++++++++++++++++++++++++
  269.  
  270. >From quinn@cs.uwa.edu.au (Quinn "The Eskimo!")
  271. Date: Sun, 23 Oct 1994 11:01:58 +0800
  272. Organization: Department of Computer Science, The University of Western
  273. Australia
  274.  
  275. In article <cwiltgen-2210941809260001@cwiltgen.pr.mcs.net>,
  276. cwiltgen@mcs.com (Charles Wiltgen) wrote:
  277.  
  278. >It's a major pain to use styled text in Apple Guide.  Basically, I can't
  279. >make any hypertext links stand out because Apple didn't think of including
  280. >an "embolden" tag in the dang compiler.
  281.  
  282. Yep, I've found this very annoying too.  I basically gave up on hot text,
  283. at least for the moment.
  284.  
  285. >What is everyone using to create Apple Guide files with?
  286.  
  287. I use TexEdit.  It's a pretty cool shareware styled text editor.  [And
  288. yes, I have sent off my shareware payment.]  Unfortunately there's no XTND
  289. filter for it, so the styles don't move across to AG.
  290.  
  291. >I'd like to use WriteNow, but the GuideMaker crashes
  292. >when it tries to read it.
  293.  
  294. I had *exactly* the same problem.  I think (god forbid) that MS Word might
  295. be a good choice.  As long as you restrict yourself to the core features
  296. it's fairly nice and the XTND filters are likely to be more stable. 
  297. However my hard disk is Microsloth-free, which eliminates this option for
  298. me.
  299.  
  300. Share and Enjoy.
  301. --
  302. Quinn "The Eskimo!"      "I wasn't the one who fired the heat seeking
  303.                           population annihilator out the window!"
  304.  
  305. +++++++++++++++++++++++++++
  306.  
  307. >From cwiltgen@mcs.com (Charles Wiltgen)
  308. Date: Sun, 23 Oct 1994 12:43:14 -0500
  309. Organization: Muso Communications
  310.  
  311. In article <quinn-2310941101580001@mac163.cs.uwa.oz.au>,
  312. quinn@cs.uwa.edu.au (Quinn "The Eskimo!") wrote:
  313.  
  314. > >It's a major pain to use styled text in Apple Guide.  Basically, I can't
  315. > >make any hypertext links stand out because Apple didn't think of including
  316. > >an "embolden" tag in the dang compiler.
  317. > Yep, I've found this very annoying too.  I basically gave up on hot text,
  318. > at least for the moment.
  319.  
  320. That's potentially one of the Best ThingsTM about Apple Guide, and we can't
  321. use it because there's no way to find out what what's hot-clickable.  I'm
  322. going to use Word on one of my smaller files (but I'm afraid!) or go to
  323. some sort of <<click here>> notation for now.
  324.  
  325. > >I'd like to use WriteNow, but the GuideMaker crashes
  326. > >when it tries to read it.
  327. > I had *exactly* the same problem.  I think (god forbid) that MS Word might
  328. > be a good choice.  As long as you restrict yourself to the core features
  329. > it's fairly nice and the XTND filters are likely to be more stable. 
  330. > However my hard disk is Microsloth-free, which eliminates this option for
  331. > me.
  332.  
  333. Thanks for the confirmation.  I got WriteNow for $12.95 when I ordered
  334. something from MacWarehouse (don't tell anyone about this special offer!)
  335. and thought it would be perfect for this.  Alas, it was not to be.
  336.  
  337. C'mon, Apple!  Add those <B>style</B> tags!!!
  338.  
  339. -- 
  340. Charles Wiltgen    "Love is a snowmobile racing across the tundra and
  341. cwiltgen@mcs.com    then suddenly it flips over, pinning you underneath.
  342. (INTP)              At night, the ice weasels come." - Nietzsche (Groening)
  343. The Apocalypso!     http://www.mcs.net/~cwiltgen
  344.  
  345. +++++++++++++++++++++++++++
  346.  
  347. >From cwiltgen@mcs.com (Charles Wiltgen)
  348. Date: Sun, 23 Oct 1994 13:41:56 -0500
  349. Organization: Muso Communications
  350.  
  351. In article <cwiltgen-2310941243140001@cwiltgen.pr.mcs.net>,
  352. cwiltgen@mcs.com (Charles Wiltgen) wrote:
  353.  
  354. > > I think (god forbid) that MS Word might
  355. > > be a good choice.  As long as you restrict yourself to the core features
  356. > > it's fairly nice and the XTND filters are likely to be more stable. 
  357. > > However my hard disk is Microsloth-free, which eliminates this option for
  358. > > me.
  359.  
  360. Nope, Word doesn't work either (although Guide reads Word files fine).
  361.  
  362. Can someone from Apple help?  I've already started doing my hot words like
  363. 'this$BB...
  364.  
  365. -- 
  366. Charles Wiltgen    "Love is a snowmobile racing across the tundra and
  367. cwiltgen@mcs.com    then suddenly it flips over, pinning you underneath.
  368. (INTP)              At night, the ice weasels come." - Nietzsche (Groening)
  369. The Apocalypso!     http://www.mcs.net/~cwiltgen
  370.  
  371. ---------------------------
  372.  
  373. >From jpo6@po.CWRU.Edu (Jared P. O'neal)
  374. Subject: Basic GWorlds and QuickDraw Newbie
  375. Date: 18 Oct 1994 21:28:47 GMT
  376. Organization: Case Western Reserve University, Cleveland, Ohio (USA)
  377.  
  378.  
  379. I've created a GWorld, at least I think I have.  Then, I used the
  380. GetGWorldPixMap() call to get the handle of the PixMap.  All I wanted to do
  381. was
  382. use CopyBits to take a picture I had put into the GWorld w/ DrawPicture onto
  383. a
  384. window I had created, but when I tried it, it didn't copy anything into the 
  385. window.  When I tried to debug it (just how do you debug a GWorld), I noticed
  386. that the baseaddr was 0, which doesn't seem right.  Is there anything I did 
  387. wrong here?  (I left out the error handling stuff)
  388.  
  389. GetGWorld(&origPort, &origDev);
  390.     myErr = NewGWorld(&myGWorldPtr, 0, &myRect, nil, nil, 0);
  391.     SetGWorld(myGWorldPtr, nil);
  392.     myPixMapHnd = GetGWorldPixMap(myGWorldPtr);
  393.     good = LockPixels(myPixMapHnd);
  394.     wndoRect = myGWorldPtr->portRect;
  395.     EraseRect(&wndoRect);
  396.  
  397. if (PictID != 0)
  398.     {
  399.         myPic = GetPicture(PictID);
  400.         DrawPicture(myPic, &myRect);
  401.     }
  402.     
  403.     SetGWorld(origPort, origDev);
  404.     
  405.     SetPort(wp);
  406.     
  407. CopyBits((BitMap *)*myPixMapHnd, (BitMap *)wp, &wndoRect, &(wp->portRect), 0,
  408. nil);
  409.  
  410. where wp is the WindowPtr of the destination window.
  411.  
  412. --Jared
  413. -- 
  414. Philosophy:  Master the colonel's secret blend of herbs & spices and all the 
  415. secrets of the universe will be yours!?!
  416.  
  417. Jared O'Neal aka jpo6@po.cwru.edu or oneale@ucsub.colorado.edu or
  418. JaredO@aol.co
  419.  
  420. +++++++++++++++++++++++++++
  421.  
  422. >From first.ascent@mindlink.bc.ca (Alex Curylo)
  423. Date: 19 Oct 1994 07:43:58 GMT
  424. Organization: First Ascent
  425.  
  426. In article <381emf$d5d@usenet.INS.CWRU.Edu>
  427. jpo6@po.CWRU.Edu (Jared P. O'neal) writes:
  428.  
  429. > Is there anything I did wrong here?
  430. >CopyBits((BitMap *)*myPixMapHnd, (BitMap *)wp, &wndoRect, &(wp->portRect),
  431. 0, nil);
  432.  
  433. Yes. (BitMap *)*myPixMapHnd is wrong. Changing that to
  434. &((GrafPtr)myGWorldPtr)->portBits should make it work just fine. And
  435. (BitMap*)wp is wrong too. You want &((GrafPtr)wp)->portBits.
  436.  
  437. +++++++++++++++++++++++++++
  438.  
  439. >From gbolsinga@aol.com (GBolsinga)
  440. Date: 19 Oct 1994 15:24:02 -0400
  441. Organization: America Online, Inc. (1-800-827-6364)
  442.  
  443. In article <382inu$idq@deep.rsoft.bc.ca>, first.ascent@mindlink.bc.ca
  444. (Alex Curylo) writes:
  445.  
  446. >Yes. (BitMap *)*myPixMapHnd is wrong. Changing that to
  447. >&((GrafPtr)myGWorldPtr)->portBits should make it work just fine. And
  448.  
  449. This is wrong! To quote NIM: Imaging With QuickDraw:
  450. "To ensure compatibility on systems running basic QuickDraw instead of
  451. Color Quickdraw, use GetGWorldPixMap whenever you need to gain
  452. access to the bitmap created for a graphics world--that is, do NOT 
  453. dereference the GWorldPtr record for that graphics world."
  454.  
  455. The funny thing is, all the code samples for CopyBIts in the book that I
  456. saw do the WRONG thing.  So many manuals, so little time... :)
  457.  
  458. The problem is with the second (destination) Bitmap: change it to:
  459.  
  460. &((GrafPtr)wp)->portBits
  461.  
  462. and thing should be fine.
  463.  
  464. Greg Bolsinga
  465. MPI Multimedia
  466.  
  467. +++++++++++++++++++++++++++
  468.  
  469. >From first.ascent@mindlink.bc.ca (Alex Curylo)
  470. Date: 24 Oct 1994 09:15:00 GMT
  471. Organization: First Ascent
  472.  
  473. In article <rac-2110941951310001@intrigue.intrigue.com>
  474. rac@intrigue.com (Robert Coie) writes:
  475.  
  476. > A word of caution about GetGWorldPixMap -- it was severely broken in
  477. > pre-7.0 systems.  I think it grabbed a half word instead of a full 32-bit
  478. > word.  If you are certain to be running on a post-7.0 system,
  479. > GetGWorldPixMap should be OK.  If you are certain that Color QuickDraw is
  480. > present and are concerned about System 6 compatibility, do the direct
  481. > dereference.
  482.  
  483. Yes indeed. Version 1.2, to be exact. Like this:
  484.  
  485.     // GetGWorldPixMap doesn't work in 32CQD 1.2
  486.     gLameCQD = (qdVersion >= gestalt32BitQD) && (qdVersion <
  487. gestalt32BitQD13);
  488.  
  489. // workaround for GetGWorldPixMap bug in CQD 1.2
  490. PixMapHandle OurGetGWorldPixMap(GWorldPtr world)
  491. {
  492.  if (gLameCQD)
  493.      return ((CGrafPtr)world)->portPixMap;
  494.  else
  495.      return GetGWorldPixMap(world);
  496. }
  497.  
  498. But in the particular case of CopyBits,
  499. &((GrafPtr)myGWorldPtr)->portBits really does always work. Up to 7.5,
  500. anyway.
  501.  
  502. ---------------------------
  503.  
  504. >From afrancke@netcom.com (Andrew Francke)
  505. Subject: CW & Code Resources -- poor?
  506. Date: Wed, 12 Oct 1994 03:00:02 GMT
  507. Organization: Netcom Online Communications Services (408-241-9760 login:
  508. guest)
  509.  
  510. After perusing CodeWarrior C for a little Component Manager
  511. development, I've formed the following reactions. Please respond with
  512. the approriate answers.
  513.  
  514. Is it just me, or:
  515.  
  516. * is there no way to create a single-segment code resource that uses
  517.   the MW ANSI libs?
  518.  
  519. * does the faux-segment loader just plain not work when the code
  520.   resource's resource fork isn't open? when there are multiple
  521.   multi-segment resources in the same file?
  522.  
  523. * is there no way to have the following declaration in an MW
  524.   code resource:
  525.  
  526.     char *foo = "bar"
  527.  
  528. If the answer to the first question is "yes," when will MW ship an
  529. intelligent linker? Yes, yes -- it's way better than the
  530. THINK/Symantec linker in its identification of dead code. That doesn't
  531. matter if it's convinced you need multiple segments based on the
  532. *un*stripped code/data size.
  533.  
  534. If the answer to any part of the second question is "yes," when will
  535. MW either: document the secret inner-workings of the multi-segment
  536. glue? Heck, if the answer is *no,* when will MW document it?
  537.  
  538. The third question is based on the fuzzy observation (i.e., I didn't
  539. ATFCO -- adjust the compiler options) that a struct with a char *
  540. member could not be initialized with a static string.
  541.  
  542. Finally -- on an entirely unrelated note -- when will somebody prepare
  543. a runtime library for MPW C-generated .o files that need such fine
  544. symbols as _iob and LDIVU -- that can then be used in MW projects.
  545.  
  546. +++++++++++++++++++++++++++
  547.  
  548. >From isochrome@aol.com (IsoChrome)
  549. Date: 13 Oct 1994 14:10:01 -0400
  550. Organization: America Online, Inc. (1-800-827-6364)
  551.  
  552. In article <afranckeCxJHo3.JD3@netcom.com>, afrancke@netcom.com (Andrew
  553. Francke) writes:
  554.  
  555. > * does the faux-segment loader just plain not work when the code
  556. >  resource's resource fork isn't open? when there are multiple
  557. >  multi-segment resources in the same file?
  558.  
  559. I've had the same problem with CW (we're writing 'cmm ' components). The
  560. component manager seems to cache the component code, so your resource fork
  561. isn't open when you are called. It looks like CW keeps some sort of jump
  562. table information in a separate resource ('cmmx' for 'cmm 's). The kiss of
  563. death is that the resource is loaded before a single line of your code is
  564. executed (to get the address of main maybe?), so there is no way you can
  565. open the resource fork yourself. I've had to punt and compile the 68K
  566. piece in Symantec and the PPC piece in CodeWarrior.
  567.  
  568. John Sarapata
  569.  
  570. +++++++++++++++++++++++++++
  571.  
  572. >From hanrek@cts.com (Mark Hanrek)
  573. Date: Sun, 16 Oct 1994 07:53:44 GMT
  574. Organization: The Information Worskhop
  575.  
  576. In article <afranckeCxJHo3.JD3@netcom.com>, afrancke@netcom.com (Andrew
  577. Francke) wrote:
  578.  
  579. Try posting your question in "comp.sys.mac.programmer.codewarrior" which
  580. you may not have known existed.  It's new, and you may find an answer to
  581. your question already posted, as I remember reading something along these
  582. lines recently.
  583.  
  584. Mark Hanrek
  585.  
  586. +++++++++++++++++++++++++++
  587.  
  588. >From richardb@cocytus.demon.co.uk (Richard Buckle)
  589. Date: Tue, 18 Oct 1994 07:51:57 GMT
  590. Organization: none
  591.  
  592. In article <afranckeCxJHo3.JD3@netcom.com>,
  593. afrancke@netcom.com (Andrew Francke) wrote:
  594.  
  595. >* is there no way to create a single-segment code resource that uses
  596. >  the MW ANSI libs?
  597.  
  598. Not if you want to use any vaguely useful ANSI function, such as pow() or
  599. tolower(). The problem is the dead-code stripping can't see through
  600. libraries.
  601. I've repeatedly suggested that MW sort this out and in the interim either
  602. distribute cut-down ANSI libraries (string.lib, math.lib etc) without
  603. 32-bit links hard-wired in or at the very least distribute a 68020 build. I
  604. have got *nowhere*.
  605.  
  606. >* does the faux-segment loader just plain not work when the code
  607. >  resource's resource fork isn't open? when there are multiple
  608. >  multi-segment resources in the same file?
  609.  
  610. Basically yes. It can also crash horribly if your multi-segment resource is
  611. unlocked between calls to it and moves, as the 32-bit jumps do not get
  612. remade. UnloadA4Seg() does not help. I have asked MW to provide a way to
  613. tell the multi-segment resource to remake its jumps, such as calling
  614. UnloadA4Seg(NULL), but this too has fallen on deaf ears. 
  615. Dammit, I feel strongly I should be entitled to unlock my code resources
  616. between calls to them.
  617. As I have no control over the third party app calling my code resource, I
  618. have been reduced to building a stub single-seg resource that calls the
  619. multi-seg resource, runs it and disposes of it to suit MW's brain-damaged
  620. segmentation scheme. Mail me if you want details.
  621.  
  622. The whole segmentation thing on CodeWarrior *sucks*, on apps as well as
  623. code resources. See a thread by Steve Dorner a while ago for a description
  624. of the pure evil that is the application segment loader under CW.
  625.  
  626. A dreadful shame, as this apart from this huge blind spot MW have a *very*
  627. fine product. Maybe some more net.pressure will do the trick.
  628.  
  629.  
  630. - -----------------------------------------------------
  631. Richard Buckle
  632. richardb@cocytus.demon.co.uk
  633. Using this darned fine NewsHopper thingy.
  634.  
  635.  
  636. +++++++++++++++++++++++++++
  637.  
  638. >From Jens Alfke <jens_alfke@powertalk.apple.com>
  639. Date: Tue, 18 Oct 1994 17:26:12 GMT
  640. Organization: Apple Computer
  641.  
  642. Andrew Francke, afrancke@netcom.com writes:
  643. > * does the faux-segment loader just plain not work when the code
  644. >   resource's resource fork isn't open? when there are multiple
  645. >   multi-segment resources in the same file?
  646.  
  647. I believe it will work as long as you preload and detach the code segments.
  648. The loader obviously can't magically know how to open the resource file to
  649. get the code.
  650.  
  651. > * is there no way to have the following declaration in an MW
  652. >   code resource:
  653. >     char *foo = "bar"
  654.  
  655. Should work fine as long as A4 is set up properly at the time that the global
  656. data is referenced.
  657.  
  658. I've directed follow-ups to c.s.m.p.codewarrior.
  659.  
  660. --Jens Alfke                           jens_alfke@powertalk.apple.com
  661.                    "A man, a plan, a yam, a can of Spam ... Bananama!"
  662.  
  663. +++++++++++++++++++++++++++
  664.  
  665. >From ejr@netcom.com (Erik J. Rogers)
  666. Date: Thu, 20 Oct 1994 01:59:30 GMT
  667. OrgathePict ) ;
  668.             oldFillCRgn = ( pascal void ( * ) ( RgnHandle ,
  669. PixPatHandle ) ) GetToolTrapAddress ( 0xaa12 ) ;
  670.             SetToolTrapAddress ( ( ProcPtr ) DrawDesk , 0xaa12 )
  671. ;
  672.         }
  673.  
  674.         theBeep = GetResource ( 'snd ' , 4000 ) ;
  675.         if ( theBeep ) {
  676.             DetachResource ( theBeep ) ;
  677.             SetToolTrapAddress ( ( ProcPtr ) DoBeep , 0xA9C8 ) ;
  678. // SysBeep
  679.         }
  680.     }
  681.     RestoreA4();
  682. }
  683.  
  684.  
  685.  
  686. --
  687.   Jon W$E4tte (h+@nada.kth.se), Hagagatan 1, 113 48 Stockholm, Sweden
  688.  
  689. "Smart Friends ask no SCSI questions!"
  690.     a Apple employee at the Bash
  691.  
  692.  
  693. ---------------------------
  694.  
  695. >From ldo@waikato.ac.nz (Lawrence D'Oliveiro, Waikato University)
  696. Subject: Drag-and-drop to cdev window?
  697. Date: 10 Oct 94 16:47:53 +1300
  698. Organization: University of Waikato, Hamilton, New Zealand
  699.  
  700. I'm writing this control panel which supports the Drag Manager. I've hit an
  701. odd problem: dragging Finder clipping files to my window doesn't seem to
  702. work.
  703.  
  704. I stepped through my drag-tracking handler with MacsBug, and watched it check
  705. for a PICT item type, by calling GetFlavorDataSize. If there is no PICT type,
  706. I get badDragFlavorErr = -1852, which makes sense. If there _is_ a PICT type,
  707. I get cantGetFlavorErr = -1854 instead.
  708.  
  709. If I drag a PICT item from another application to my control panel window,
  710. it works OK, so I figure a bug in my code is unlikely. :-)
  711.  
  712. Anybody else encountered this? Maybe the problem is that control panels
  713. run in the Finder's context, and its peculiar uses of the Drag Manager don't
  714. allow for this.
  715.  
  716. Any ideas welcomed.
  717.  
  718. Lawrence D'Oliveiro                       fone: +64-7-856-2889
  719. Info & Tech Services Division              fax: +64-7-838-4066
  720. University of Waikato            electric mail: ldo@waikato.ac.nz
  721. Hamilton, New Zealand    37^ 47' 26" S, 175^ 19' 7" E, GMT+13:00
  722.  
  723. +++++++++++++++++++++++++++
  724.  
  725. >From jumplong@aol.com (Jump Long)
  726. Date: 11 Oct 1994 01:03:03 -0400
  727. Organization: America Online, Inc. (1-800-827-6364)
  728.  
  729. In article <1994Oct10.164754.34014@waikato.ac.nz>, ldo@waikato.ac.nz
  730. (Lawrence D'Oliveiro, Waikato University) writes:
  731.  
  732. >I'm writing this control panel which supports the Drag Manager. I've hit
  733. >an odd problem: dragging Finder clipping files to my window doesn't seem
  734. >to work.
  735.  
  736. We had the same report at work and the answer is, it won't work.  I can't
  737. remember the reason why, but Nitin tracked it down.
  738.  
  739. - Jim Luther
  740.  
  741. ---------------------------
  742.  
  743. >From rej@chinook.halcyon.com (Randy Jones)
  744. Subject: Fastest way to fill memory with a given value?
  745. Date: 14 Oct 1994 17:58:54 GMT
  746. Organization: NWNEXUS, Inc. - We Make Internet Easy
  747.  
  748. I want to fill a given block of memory with copies of a long.
  749. I'm guessing there has to be a faster way than a loop which
  750. sets each word in turn.  BlockMove, for example, runs faster
  751. than a copy loop.  But there's no Mac toolbox equivalent of 
  752. memset that I've found.  
  753.  
  754. Are compilers smart enough to turn my loop of word writes into 
  755. something faster, maybe involving the MMU?  If not, then what
  756. am I missing?  Think and/or MetroWerks C, BTW.
  757.  
  758. --Randy Jones
  759.  
  760.  
  761.  
  762. +++++++++++++++++++++++++++
  763.  
  764. >From relmore@halcyon.com (Richard Elmore)
  765. Date: Sat, 15 Oct 1994 01:54:09 -0800
  766. Organization: Northwest Nexus Inc.
  767.  
  768. In article <37mgsu$opv@news.halcyon.com>, rej@chinook.halcyon.com (Randy
  769. Jones) wrote:
  770.  
  771. > I want to fill a given block of memory with copies of a long.
  772. > I'm guessing there has to be a faster way than a loop which
  773. > sets each word in turn.  BlockMove, for example, runs faster
  774. > than a copy loop.  But there's no Mac toolbox equivalent of 
  775. > memset that I've found.  
  776.  
  777. The most common way to speed up mem copy/fill operations is to unroll your
  778. loop.  That is, instead of copying one long word during each iteration of
  779. your loop copy several.  This is in fact the approach taken by
  780. _BlockMove.  Another thing that will make a difference is to make sure all
  781. of your moves are longword aligned (ever notice how Hypercard snaps its
  782. windows an invisible grid on the screen, thats why).
  783.  
  784. -- 
  785. Richard Elmore
  786. relmore@halcyon.com
  787.  
  788. +++++++++++++++++++++++++++
  789.  
  790. >From Arnold Kim <ahk12@columbia.edu>
  791. Date: 16 Oct 1994 20:26:04 GMT
  792. Organization: Nemesis Productions
  793.  
  794. In ttribute bits will keep appearing as the system software develops...
  795.  
  796. The note about the gestaltKeyboardType selector not being installed on
  797. the PowerMac 7100/66 was triggered by an Usenet posting by Marc Cooperman.
  798. His observation was confirmed by me because Gestalt! reports of the
  799. PM 7100/66 indeed do not list this selector, but I never noticed this when
  800. I received these reports! Other (Power)Macs don't seem to have this
  801. problem.
  802.  
  803. The GSL has been made available by Robert Lentz on a World Wide Web server.
  804. It now has the latest version and a reference to it is included with the
  805. 'About This List/Availability' section.
  806.  
  807. Included information from the:
  808.  - Bookmark CD #18,
  809.  - Bookmark CD #19,
  810.  - WWDC 1994 CD,
  811.  - Developer CD Series August 1994 Tool Chest CD and
  812.  - Developer CD Series September 1994 Reference Library CD.
  813.  
  814. Roland Mansson provided the information from the latest Gestalt &
  815. SysEnvirons TechNote (rev. September 1994). The most important news
  816. is that the machine ID's will be reused...
  817.  
  818. The following selectors are now installed with software included with
  819. System 7.5 and are moved from the 'Apple Additional Software' to the 'Apple
  820. System Software' section:
  821.       ascr, ascv, aucd, cpkr,
  822.       drag, hscd, icmp, iscd,
  823.       kpcd, mtcp, qtim, qtrs,
  824.       scra, sdev, sdvr, snhw,
  825.       teat, thds, ufox, xlat
  826. And these from the unknown 'Third Party Software' to the unknown 'Apple
  827. Software' section:
  828.       CDJR, HAM , MClk
  829. ***************************************************************************
  830.  
  831.  
  832. Best regards,
  833. Rene Ros
  834. rgaros@bio.vu.nl
  835.  
  836. -- 
  837.   Rene G.A. Ros           rgaros@bio.vu.nl          Amsterdam, The
  838. Netherlands
  839. -
  840. ------------------------------------------------------------------------------
  841.  
  842.   English is deliberately designed to frustrate foreigners, you know...
  843.   (Jeremy Roussak (UK) while trying to explain 'an/a' to me)
  844.  
  845. ---------------------------
  846.  
  847. >From danmcd@sundance.itd.nrl.navy.mil (Dan McDonald)
  848. Subject: Global storage in code resources
  849. Date: 14 Oct 1994 17:13:29 GMT
  850. Organization: Information Technology Division, Naval Research Laboratory
  851.  
  852.  
  853. With the advent of PowerPC, I'm again confused on something I thought I
  854. knew.
  855.  
  856. I assumed that:
  857.  
  858.     * Global variables between procedures in a separate code resource
  859.       were okay, as long as A4 was set up properly
  860.  
  861. If that assumption was wrong, fine.  If it's right, then
  862.  
  863.     * How the HELL do you set up A4 in PowerPC code resources?
  864.  
  865. I may end up designing my external code modules such that the module asks
  866. the main program for storage, and the main program delivers, and
  867. subsequently sends pointers to it whenever the code in the module is called.
  868.  
  869. Any comments, hints, death threats, etc. are vastly appreciated.
  870. -- 
  871. Daniel L. McDonald | Mail:  danmcd@itd.nrl.navy.mil
  872. -------------------------+
  873. Computer Scientist | WWW:   http://wintermute.itd.nrl.navy.mil/danmcd.html  
  874. |
  875. Naval Research Lab | Phone: (202) 404-7122        #include <disclaimer.h>   
  876. |
  877. Washington, DC     | "Rise from the ashes, A blaze of everyday glory" - Rush
  878. +
  879.  
  880. +++++++++++++++++++++++++++
  881.  
  882. >From isis@netcom.com (Mike Cohen)
  883. Date: Sat, 15 Oct 1994 19:09:29 GMT
  884. Organization: ISIS International
  885.  
  886. In article <37me7q$b40@ra.nrl.navy.mil>, danmcd@sundance.itd.nrl.navy.mil
  887. (Dan McDonald) wrote:
  888.  
  889. > With the advent of PowerPC, I'm again confused on something I thought I
  890. > knew.
  891. > I assumed that:
  892. >         * Global variables between procedures in a separate code resource
  893. >           were okay, as long as A4 was set up properly
  894. > If that assumption was wrong, fine.  If it's right, then
  895. >         * How the HELL do you set up A4 in PowerPC code resources?
  896. 68K code resources still need to have A4 set up, but you don't have to do
  897. anything in native code resources. In PPC code, every code fragment
  898. (including code resources) has its own global space accessible thru the
  899. RTOC, which a register is always pointing to when that code fragment is
  900. executing.
  901.  
  902. -- 
  903. Mike Cohen - isis@netcom.com
  904. NewtonMail, eWorld: MikeC / ALink: D6734 / AOL: MikeC20
  905. Home Page: ftp://ftp.netcom.com/pub/isis/home.html
  906.  
  907. ---------------------------
  908.  
  909. >From zack@netcom.com (Zack T. Smith)
  910. Subject: How to execute MPW tools without MPW
  911. Date: Wed, 12 Oct 1994 13:58:39 GMT
  912. Organization: NETCOM On-line Communication Services (408 261-4700 guest)
  913.  
  914. Hi,
  915.  
  916. I'd like to find out how I can execute MPW commands without
  917. having MPW. I know that there is a program available for
  918. doing this (toolserver), but I don't want to use it.
  919.  
  920. I notice that the MPW tool that I have (gcc) contains only code 
  921. and version resources. I've tried to execute that as a 
  922. standalone app by changing creator to FNDR and type to APPL, 
  923. but the program immediately exits.
  924.  
  925. Does anyone know why this might be happening, assuming that gcc
  926. is not buggy. I've tried to inquire with Apple via email, but 
  927. they won't respond. My guess is that, if gcc had been
  928. executing properly, it simply didn't find any params to work on,
  929. so it exited. 
  930.  
  931. Would anyone know whether it's necessary to load MPW tools 
  932. into memory in order to execute them and pass parameters?
  933.  
  934. Thanks for any info,
  935.  
  936. Zack Smith
  937.  
  938.  
  939. +++++++++++++++++++++++++++
  940.  
  941. >From shebs@cygnus.com (Stan Shebs)
  942. Date: Wed, 12 Oct 1994 18:52:22 GMT
  943. Organization: /cygint/s1/users/shebs/.organization
  944.  
  945.  
  946. In article <zackCxKC5s.Jnx@netcom.com> zack@netcom.com (Zack T. Smith)
  947. writes:
  948.  
  949.    I notice that the MPW tool that I have (gcc) contains only code 
  950.    and version resources. I've tried to execute that as a 
  951.    standalone app by changing creator to FNDR and type to APPL, 
  952.    but the program immediately exits.
  953.  
  954. Uh, MPW GCC requires considerable MPW infrastructure - for one thing,
  955. it is a collection of tools, for another, it expects to be able to use
  956. the MPW Assembler.  And where do you plan to get include files and
  957. libraries?  Changing the file type to get it to run is about like
  958. working the shift lever on an engineless car - it *might* start
  959. rolling if you happen to shift into neutral while on a downhill slope...
  960.  
  961. MPW GCC needs a full MPW environment in order to be used.  Jonathan
  962. Kimmitt has hacked up a standalone version, but it has a number of
  963. limitations (the last time I looked, it couldn't build itself, for
  964. instance).
  965.  
  966.    Does anyone know why this might be happening, assuming that gcc
  967.    is not buggy. I've tried to inquire with Apple via email, but 
  968.    they won't respond. My guess is that, if gcc had been
  969.    executing properly, it simply didn't find any params to work on,
  970.    so it exited. 
  971.  
  972. It's not that "Apple won't respond", it's that there's nobody there
  973. *to* respond.  MPW GCC is not an Apple product, it was a project I
  974. did while in Apple's ATG (and as you might guess from the address below,
  975. I'm no longer there).  If you use it with MPW, it works just fine.
  976.  
  977. (For those more knowledgeable who might be wondering, yes Cygnus
  978. would be willing to do an updated Mac GCC, *if* appropriate funding
  979. were to be provided - I have no spare time these days :-( )
  980.  
  981.                             Stan Shebs
  982.                             Cygnus Support
  983.                             shebs@cygnus.com
  984.  
  985. +++++++++++++++++++++++++++
  986.  
  987. >From jwbaxter@olympus.net (John W. Baxter)
  988. Date: Wed, 12 Oct 1994 09:52:59 -0700
  989. Organization: Internet for the Olympic Peninsula
  990.  
  991. In article <zackCxKC5s.Jnx@netcom.com>, zack@netcom.com (Zack T. Smith)
  992. wrote:
  993.  
  994. > Hi,
  995. > I'd like to find out how I can execute MPW commands without
  996. > having MPW. I know that there is a program available for
  997. > doing this (toolserver), but I don't want to use it.
  998. > I notice that the MPW tool that I have (gcc) contains only code 
  999. > and version resources. I've tried to execute that as a 
  1000. > standalone app by changing creator to FNDR and type to APPL, 
  1001. > but the program immediately exits.
  1002.  
  1003. MPW (and ToolServer) provides a considerable amount of environment in
  1004. which MPW tools operate.  (Including in MPW's case a "foreign file system"
  1005. so that the tool access the current content of a window being edited, when
  1006. it thinks it is opening a file by that name.)
  1007.  
  1008. What you want to do is not impossible (witness Think/Symantec's SARez and
  1009. SADerez, which are apps which provide the needed environment), but more
  1010. trouble than it's worth.
  1011.  
  1012.    --John
  1013.  
  1014. -- 
  1015. John Baxter    Port Ludlow, WA, USA  [West shore, Puget Sound]
  1016.    Sorry..I would probably load the resources once, image them into
  1017.         offscreen graphics worlds and then just CopyBits in
  1018.         DoAnimation. Lots of sample code available to do this BTW.
  1019.  
  1020. > Well, the problem is that under a low memory condition (say ~7,000 - 
  1021. > 8,000 bytes free), the first picture is loaded and displays fine, but 
  1022. > when the second image is loaded, my app crashes...
  1023.  
  1024.         How do you know how much memory you have free?
  1025.  
  1026. >  
  1027. > I then went in and added a
  1028. >     ReleaseResource( (Handle )pic);
  1029. > This time, each of the four pictures were loaded (and my app didn't crash)
  1030.  
  1031.         This should be a clue... (what has changed? why did that
  1032.         make a difference?... are your PICT resources marked
  1033.         purgeable?)
  1034.  
  1035. > ...but when the counter turned back to 0, the first pic wasn't displayed.
  1036. >  
  1037. > I dismissed the dialog box and brought it back up again.  This time, none 
  1038. > of the pictures were displayed!  Well, this leads me to believe that when 
  1039. > I call ReleaseResource(), it not only frees up the memory of the handle 
  1040. > holding the picture, but it clears it from the current resource as well.  
  1041. > I then tried to use the DisposeHandle() call in place of the 
  1042. > ReleaseResource() call, and the same thing occurred (all four pictures 
  1043. > were displayed once and only once).
  1044. >  
  1045. > At this point, I added following:
  1046. >  
  1047.  if (pic != nil) {
  1048.        ...
  1049.  } else {
  1050. >     MoveTo(20, 20);
  1051. >     DrawString("\pCan't open image");
  1052. > }
  1053. >  
  1054. > the error message never came up!
  1055. >  
  1056. > So what gives?  I can't load and display the image, yet the pic isn't nil 
  1057. > either!?!?!  
  1058. >  
  1059.  
  1060.         There were three statements in that last line.
  1061.  
  1062.         1) I can't load the image
  1063.         2) I can't display the image
  1064.         3) The handle to the image is not nil
  1065.  
  1066.         These can not all be true. GetPicture returns nil if it
  1067.         was unable to load the image. Since you say "the error
  1068.         message never came up" I will assume that 3 is true. This
  1069.         means that 1 must be false. This leaves only 2 as a
  1070.         problem for your application. This is what you must
  1071.         investigate.
  1072.  
  1073.         BTW, have you investigated how QuickDraw reports errors.
  1074.         Given that it appears that this "feature" is occurring in
  1075.         the DrawPicture call, how would you know that it failed?
  1076.         Apart from not being able to see the picture.
  1077.  
  1078. > Do I need to do a lot of watch dogging and not let any operations be 
  1079. > performed if the app goes beneath 0k of memory is free?
  1080. >  
  1081.  
  1082.         You have less than 0k of memory free and expect the
  1083.         program to do something?
  1084.  
  1085.         BTW, just to be a total smart-***, the generally accepted
  1086.         way to handle this type of situation is to:
  1087.  
  1088.         1) Figure out how much memory you application needs.
  1089.         2) Make sure that it gets at least that much.
  1090.  
  1091.         ;^) <--- note the smiley!
  1092.  
  1093. >  
  1094. > 3) In Macintosh C Programming Primmer Vol 2, it states that when a 
  1095. > program starts, it contains a block of master pointers.  It is within 
  1096. > this location that the location of the Handles are kept (64 of them).  If 
  1097. > the program requires more than 64, the MoreMasters() call needs to be 
  1098. > made (which will create 64 more locations for handles).  What happens if 
  1099. > I have filled up all 64 locations with handles, then create another 
  1100. > handle (for arguments' sake, let's say that there is enough memory to 
  1101. > create the size of the handle, and we create a new handle without 
  1102. > calling MoreMasters())?  Will I run the risk of loosing the handle when 
  1103. > memory is juggled around?
  1104. >  
  1105.  
  1106.         If you call NewHandle, and you have no more master
  1107.         pointers available, NewHandle will call MoreMasters for
  1108.         you. The point behind doing it youself is that master
  1109.         pointer blocks are non-relocatable and tend to lead to
  1110.         heap fragmentation. 
  1111.  
  1112.         If you let NewHandle make the call, the master pointer
  1113.         block will be placed as low in the heap as possible.
  1114.         Depending on what you have been doing, you may have
  1115.         relocatable or purgeable structures in heap below that
  1116.         block. If you want to reuse tpp, if the
  1117. memory gets below 10k or 12k, I am going to inform the user that there is
  1118. not enough, and that they should close a file.
  1119.  
  1120.  
  1121. >>
  1122. >> 2) I am loading four separate pictures...
  1123. >>
  1124. >void DoAnimation(short step) {
  1125. >    PicHandle    pic = GetPicture(128+step);
  1126. >    if (pic != nil) DrawPicture(pic, &(**pic).portRect);
  1127. >}
  1128.  
  1129. >>
  1130. >> Looks good so far, no?
  1131.  
  1132. >        Well, no. I would guess this flashes like mad (but if you
  1133. >        haven't gotten it to work yet, you wouldn't know that ;^).
  1134. >        I would probably load the resources once, image them into
  1135. >        offscreen graphics worlds and then just CopyBits in
  1136. >        DoAnimation. Lots of sample code available to do this BTW.
  1137.  
  1138. Well, I guess you missed my point.  Yes, the function works
  1139. fine (if there is enough memory available).  For right now, I'm not
  1140. calling my animation at a set interval, so YES, obviously on faster CPUs it
  1141. will be 'FLASHED'.  Yes, I'm am going to put in a timer, so the interval is
  1142. standard from one machine to another.
  1143.  
  1144. I do know how to use CopyBits and off screen GWorlds.  For this portion
  1145. of the code, it is redundant.  Why?  I don't want to permanently 'hold'
  1146. the pictures... all I need is one picture drawn to the screen at a time
  1147. (therefore, I don't feel I need to hold all four).  Holding the bits in
  1148. an offscreen gworld would mean I am using twice the memory for the images:
  1149. one for the resource and one for the offscreen memory
  1150.  
  1151.  
  1152. >> Well, the problem is that under a low memory condition (say ~7,000 -
  1153. >> 8,000 bytes free), the first picture is loaded and displays fine, but
  1154. >> when the second image is loaded, my app crashes...
  1155.  
  1156. >        How do you know how much memory you have free?
  1157.  
  1158. There is a call called FreeMem() which I am using to output the free
  1159. memory.  I am also using a utility called SWATCH (System Watch) which
  1160. graphically & numerically displays the amount of locked used memory,
  1161. moveable used memory, and free memory each app is using.
  1162.  
  1163.  
  1164. >>
  1165. >> I then went in and added a
  1166. >>      ReleaseResource( (Handle )pic);
  1167. >> This time, each of the four pictures were loaded (and my app didn't crash)
  1168.  
  1169. >        This should be a clue... (what has changed? why did that
  1170. >        make a difference?... are your PICT resources marked
  1171. >        purgeable?)
  1172.  
  1173. Yes, it was a clue.  It was telling me that not only the handle was being
  1174. released, but the location of the resource was being released as well.
  1175. That is why I was only able to display each image once (and only once).
  1176. No, I was not marking the pictures within the resource as being
  1177. purgeable, but I am now doing HPurge( (Handle pic ) after the
  1178. DrawPicture call... it works..... better, but it still crashes (better in
  1179. the sence that if I set my app to run with ~ 12k free and call my dialog
  1180. it works, but if memory gets below 6k, it crashes... looks like I will
  1181. definately have to work on this a bit.
  1182.  
  1183. The point I was trying to make was this:
  1184.  
  1185. If I perform a DisposeHandle on a pic handle, how come I am not able to
  1186. load and display the picture a second time?  DisposeHandle should just
  1187. remove the handle, not the resouce, shouldn't it?
  1188.  
  1189. The other point I was trying to make was this:  If I can get the image
  1190. (and pic != nil), how come I am not able to display it?  If GetPicture
  1191. failed, it's supposed to return a 0, yet it doesn't, so what gives?
  1192.  
  1193.  
  1194. >>
  1195. >> At this point, I added following:
  1196. >>
  1197. > if (pic != nil) {
  1198. >       ...
  1199. > } else {
  1200. >>      MoveTo(20, 20);
  1201. >>      DrawString("\pCan't open image");
  1202. >> }
  1203. >>
  1204. >> the error message never came up!
  1205. >>
  1206. >> So what gives?  I can't load and display the image, yet the pic isn't nil
  1207. >> either!?!?!
  1208. >>
  1209.  
  1210. >        There were three statements in that last line.
  1211.  
  1212. >        1) I can't load the image
  1213. >        2) I can't display the image
  1214. >        3) The handle to the image is not nil
  1215.  
  1216. >        These can not all be true. GetPicture returns nil if it
  1217. >        was unable to load the image. Since you say "the error
  1218. >        message never came up" I will assume that 3 is true. This
  1219. >        means that 1 must be false. This leaves only 2 as a
  1220. >        problem for your application. This  and refer you to further
  1221. >        reading, so that you can learn the material yourself and
  1222. >        not have to ask again next time.
  1223.  
  1224. Pretty close.  I've been programming for several years and have
  1225. programmed several different operating systems (Unix, Atari ST/GEM,
  1226. Windows, now Mac).  I've been programming the Mac for ~ 6 months in my
  1227. spare time.  The biggest problems I have encountered w/the Mac are:
  1228.  
  1229. 1 Unconventional.  I'm not taliking about event-driven programming
  1230. conceps, but things like string types.  Who the hell even USES Str63 or
  1231. Str255?!?!???  After years of honning my pointer & string skills, I have
  1232. to deal with this junk.  If I write my own function, I use pointers, if I
  1233. use a toolbox call, well... I use  StrXXX.  And linked lists... try doing
  1234. a linked list on the Mac... I DARE YOU.
  1235.  
  1236. 2 There are several good Mac programming books out there, but all only
  1237. cover the basics.  What I'd like to see is something that covers a full
  1238. scale real world type app.  One that covers such topics as Multiple
  1239. files/windows opened at a time, localization, printing, error-proofing
  1240. apps, etc...  I've seen some books that start to deal with some of these 
  1241. topics, but don't go into very much depth on them.
  1242.  
  1243. 3 Example code base is meeger.  There are several areas of Mac programming
  1244. which need some indepth examples.  The app which I'm writing shouldn't
  1245. have taken this long, but I got locked up on a couple topics.
  1246.  
  1247.  
  1248. >        (new) Inside Macintosh: Memory - for references to
  1249. >        questions about: MoreMasters, NewHandle, CompactMem,
  1250. >        PurgeMem, FreeMem, etc.
  1251.  
  1252. Don't have it, but I have THINK Reference.
  1253.  
  1254.  
  1255. >        (new) Inside Macintosh: Imaging with QuickDraw - for
  1256. >        references to questions about: DrawPicture, GetPicture,
  1257. >        etc.
  1258.  
  1259.  
  1260. Have it.
  1261.  
  1262. >--
  1263.  
  1264. >Hope this helps.
  1265.  
  1266.  
  1267. a little
  1268.  
  1269.  
  1270. Jeff
  1271.  
  1272.  
  1273.  
  1274. +++++++++++++++++++++++++++
  1275.  
  1276. >From gbolsinga@aol.com (GBolsinga)
  1277. Date: 18 Oct 1994 17:41:08 -0400
  1278. Organization: America Online, Inc. (1-800-827-6364)
  1279.  
  1280. In article <380uvh$lqm@nntp1.u.washington.edu>, jbeeghly@u.washington.edu
  1281. (Jeff Beeghly) writes:
  1282.  
  1283. >If I perform a DisposeHandle on a pic handle, how come I am not able to
  1284. >load and display the picture a second time?  DisposeHandle should just
  1285. >remove the handle, not the resouce, shouldn't it?
  1286.  
  1287. This is bad.  Use KillPicture for all PICTs that aren't resources.
  1288. Use ReleaseResource for all other PICTs.
  1289.  
  1290. Greg
  1291. MPI Multimedia
  1292.  
  1293.  
  1294. +++++++++++++++++++++++++++
  1295.  
  1296. >From bj@lamar.colostate.edu (B.J. Buchalter)
  1297. Date: Tue, 18 Oct 1994 17:10:45 -0700
  1298. Organization: CSU Physics Department
  1299.  
  1300. In article <380uvh$lqm@nntp1.u.washington.edu>, jbeeghly@u.washington.edu
  1301. (Jeff Beeghly) wrote:
  1302.  
  1303.  
  1304. >  
  1305. > I've received one reply that stated all standard system calls will most
  1306. > likely crash when memory gets too low.  Therefore, in my app, if the
  1307. > memory gets below 10k or 12k, I am going to inform the user that there is
  1308. > not enough, and that they should close a file.
  1309. >  
  1310.  
  1311. Yes, this is important. Basically, your strategy needs to be that if the
  1312. amount of free memory gets to be too small (e.g. sufficently small that
  1313. operations WILL fail), you need to disable all of the commands that will
  1314. cause memory to be allocated. That is, if you don;t have enough memory for
  1315. the about box, disable the about box command. Similarly, if you are really
  1316. low on memory, don't allow the user to open another file, and perhaps ask
  1317. them to close one, or ask them to do something else that will free up
  1318. memory.
  1319.  
  1320.  
  1321. > If I perform a DisposeHandle on a pic handle, how come I am not able to
  1322. > load and display the picture a second time?  DisposeHandle should just
  1323. > remove the handle, not the resouce, shouldn't it?
  1324.  
  1325. You definitely do not want to use DisposeHandle on a resource. The
  1326. Resource Manager keeps a table of which resources are loaded and where
  1327. they are in memory. The Memory Manager keeps a table(s) of which handles
  1328. are allocated and where they are in memory. If you tell the resource
  1329. manager to release the resource it cleans up its table and marks the
  1330. resource purgable. If you tell the memory manager to Dispose the handle,
  1331. here either wasn't enough memory to load the resource, or the resource
  1332. was purged.  If the first dereference is NULL, call LoadResource to see
  1333. if you can load it.  Code that I use for loading any handle looks like
  1334. this:
  1335.  
  1336.     Handle h = GetResource('XXXX', id);
  1337.  
  1338.     if (h)            // resource exists?
  1339.     {
  1340.         if (!*h)
  1341.             LoadResource(h);
  1342.  
  1343.         if (*h)
  1344.         {
  1345.             // use the resource
  1346.         }
  1347.  
  1348.         ReleaseResource(h);            // or HPurge(h) is
  1349. even better!
  1350.     }
  1351.  
  1352. >The biggest problems I have encountered w/the Mac are:
  1353. >1 Unconventional.  I'm not taliking about event-driven programming
  1354. >conceps, but things like string types.  Who the hell even USES Str63 or
  1355. >Str255?!?!???  After years of honning my pointer & string skills, I have
  1356. >to deal with this junk.  If I write my own function, I use pointers, if I
  1357. >use a toolbox call, well... I use  StrXXX.  And linked lists... try doing
  1358. >a linked list on the Mac... I DARE YOU.
  1359.  
  1360. No problem.  I use linked lists all the time.  Pointer AND Handles.
  1361.  
  1362. >2 There are several good Mac programming books out there, but all only
  1363. >cover the basics.  What I'd like to see is something that covers a full
  1364. >scale real world type app.  One that covers such topics as Multiple
  1365. >files/windows opened at a time, localization, printing, error-proofing
  1366. >apps, etc...  I've seen some books that start to deal with some of these 
  1367. >topics, but don't go into very much depth on them.
  1368.  
  1369. I agree.  I've been thinking about that one for a while.  Especially
  1370. printing.  Printing is *EASY* on the Mac.  Try writing a simple printable
  1371. app for Windows -- what a NIGHTMARE!  For example, under Windows, you
  1372. have to do your own scaling (Move and Line are
  1373. device-resolution-specific, but Ellipse and such are based upon the
  1374. current scaling factor set).  I also found a major bug in printing
  1375. landscape (on an HP PCL printer) -- the same code which worked correctly
  1376. when printing portrait broke badly when printing landscape.  Items were
  1377. moved, portions of graphic items were drawn in different places on the
  1378. page (for example, half of an ellipse was drawn in one spot, the other
  1379. half was drawn in another spot, and there was white space between the two
  1380. halves!).  I ended up writing my own landscape code, and letting the
  1381. print drivers (plural -- each printer does its own print code) tell me
  1382. whether I should do my landscaping code.  That bug alone took two months
  1383. to find, diagnose and fix, because, although you can rotate text, many of
  1384. the parts of Windows GDI break down when dealing with vertical rather
  1385. than horizontal text.
  1386.  
  1387. >3 Example code base is meeger.  There are several areas of Mac
  1388. programming
  1389. >which need some indepth examples.  The app which I'm writing shouldn't
  1390. >have taken this long, but I got locked up on a couple topics.
  1391.  
  1392. I definately agree on this one, especially some of the newer managers! 
  1393. However, many of the newer managers (that are extensive, like AOCE or
  1394. QDGX) have many example programs to search through to find the answers to
  1395. many questions.
  1396.  
  1397. However, it has been my experience that Windows programming examples are
  1398. even scarcer -- I had to find PD applications which addressed some of the
  1399. same issues I had to deal with!  Microsoft basically doesn't provide
  1400. anything easily accessable, and although Borland did provide some sample
  1401. code with their compiler, most of it had to do with the "bells &
  1402. whistles" of Windows, like OLE, MCI, and so forth, but very little on
  1403. standard "how to display a window contents and deal with scroll bars."  I
  1404. basically had to experiment with that until I got it right -- another two
  1405. months down the drain.
  1406.  
  1407. The same basic program that I wrote under Windows which took 12 months to
  1408. write and debug took 1 weekend (that's less than 40 hrs, folks!) to write
  1409. using Symantec C++ and TCL.  Much of the stuff I got for free on the
  1410. Macintosh.  Much of the stuff I had to write under Windows...
  1411. //
  1412. // Glenn L. Austin
  1413. // Computer Wizard and Racing Car Driver
  1414. // Internet:  glenn_a@efn.org
  1415. //
  1416.  
  1417. +++++++++++++++++++++++++++
  1418.  
  1419. >From Jaeger@fquest.com (Brian Stern)
  1420. Date: 19 Oct 1994 17:25:21 GMT
  1421. Organization: The University of Texas at Austin, Austin, Texas
  1422.  
  1423. In article <380uvh$lqm@nntp1.u.washington.edu>, jbeeghly@u.washington.edu
  1424. (Jeff Beeghly) wrote:
  1425.  
  1426. <  
  1427. <  
  1428. < >> Do I need to do a lot of watch dogging and not let any operations be
  1429. < >> performed if the app goes beneath 0k of memory is free?
  1430. < >        You have less than 0k of memory free and expect the
  1431. < >        program to do something?
  1432. <  
  1433. < That was a typo.  It should have been 10k free.
  1434. <  
  1435. < >        BTW, just to be a total smart-***, the generally accepted
  1436. < >        way to handle this type of situation is to:
  1437. <  
  1438. < >        1) Figure out how much memory you application needs.
  1439. < >        2) Make sure that it gets at least that much.
  1440. <  
  1441. < >        ;^) <--- note the smiley!
  1442. <  
  1443. < Yep.  Verry standard.  But the problem is this:  My app will handle an
  1444. < unlimited number of files/windows (memory permitting).  I do not wish to
  1445. < limit the user by only allowing them a max number of files open at a time
  1446. < (like 5 or 10).  Each window/file at it's maximum will use ~ 55 handles
  1447. < (I'm displaing a max of 50 icons, each is contained within an IconSuite,
  1448. < which is a handle).  If I plan on having 5 files open, I should probably
  1449. < call MoreMasters 4 times.  If I plan on having 10 files open, I should
  1450. < probably call MoreMasters 9 times.
  1451. <  
  1452. < Get my point?
  1453. <  
  1454. < It's varriable depending on the user.  Ideally it would be nice to Call a
  1455. < MoreMasters() call before I open a file, then do a DeleteMoreMasters call
  1456. < (if such a call had existed) after I calosed a file.  These are all
  1457. < design issues I will have to iron out I guess.
  1458. <  
  1459. <  
  1460.  
  1461. Most of the sample code I've seen uses a size of about 40K as the time to
  1462. post a low memory warning.  Since we're talking about 'Real World' apps
  1463. you should know that ALL real world apps have a growZone procedure and use
  1464. some mechanism for keeping a buffer of memory available.  Usually this
  1465. done by a mechanism known as the rainy-day fund.  Briefly, at app startup
  1466. you allocate a handle of, say, 40K.  That's your rainy day fund.  Each
  1467. time through your main event loop ( or perhaps only on null events) you
  1468. check the available memory.  If it's too low you post a warning alert. 
  1469. Under some circumstances you release the rainy day handle.  Either from
  1470. your growZone Proc or possibly in response to an explicit call from
  1471. somewhere in your app.
  1472.  
  1473. Regarding the MoreMasters calls.  Exercise your app thoroughly with a
  1474. number of windows/documents open that is on the high side of what you
  1475. would consider avaerage.  See how many Master Pointer blocks were needed. 
  1476. Maybe add 2 or 3 to this number and call MoreMasters this many times. 
  1477. Eight or ten should be more than sufficient.  Realize that any user that
  1478. sees the 'not enough memory' warning is going to up the partition size for
  1479. the app.  Although this doesn't automatically increase the number of
  1480. Master Pointer blocks it does give the app more breathing room so that if
  1481. any are automatically allocated any problems caused by heap fragmentation
  1482. are minimized.  The important thing is to warn when memory gets low.
  1483.  
  1484.  
  1485. <   The biggest problems I have encountered w/the Mac are:
  1486. <  
  1487. < 1 Unconventional.  I'm not taliking about event-driven programming
  1488. < conceps, but things like string types.  Who the hell even USES Str63 or
  1489. < Str255?!?!???  After years of honning my pointer & string skills, I have
  1490. < to deal with this junk.  If I write my own function, I use pointers, if I
  1491. < use a toolbox call, well... I use  StrXXX.  And linked lists... try doing
  1492. < a linked list on the Mac... I DARE YOU.
  1493.  
  1494. Gee Jeff, we were just beginning to like you, and then you turn on us like
  1495. this:)  Are you aware that your windowlist is a linked list?  There are
  1496. numerous operating system queues that are linked lists.  Doing linked
  1497. lists with memory allocated by NewPtr or by malloc is no different than on
  1498. any other architecture.  You can do linked lists with handles.  The only
  1499. difference is an extra * here or there when referring to the memory
  1500. blocks.
  1501.  
  1502. If you're not aware, the reason for the Str255 and friends string types
  1503. are due to the Mac's Pascal heritage.  Don't complain about it, just
  1504. accept it.  Every development environment has utility routines to
  1505. translate between C and P strings.  Sorry you had to learn something new.
  1506.  
  1507. <  
  1508. < 2 There are several good Mac programming books out there, but all only
  1509. < cover the basics.  What I'd like to see is something that covers a full
  1510. < scale real world type app.  One that covers such topics as Multiple
  1511. < files/windows opened at a time, localization, printing, error-proofing
  1512. < apps, etc...  I've seen some books that start to deal with some of these 
  1513. < topics, but don't go into very much depth on them.
  1514. <  
  1515. < 3 Example code base is meeger.  There are several areas of Mac programming
  1516. < which need some indepth examples.  The app which I'm writing shouldn't
  1517. < have taken this long, but I got locked up on a couple topics.
  1518.  
  1519. Are you aware of the sample code at ftp.apple.com and at the
  1520. alt.sources.mac archive at ftp://ftpbio.bgsu.edu/?
  1521.  
  1522. <  
  1523. <  
  1524. <  
  1525. < Have it.
  1526. <  
  1527. < >--
  1528. <  
  1529. < >Hope this helps.
  1530. <  
  1531. <  
  1532. < a little
  1533. <  
  1534. <  
  1535. < Jeff
  1536.  
  1537. Good luck,
  1538.  
  1539. -- 
  1540. Brian  Stern  :-{)}
  1541. Toolbox commando and Menu bard
  1542. Jaeger@fquest.com
  1543.  
  1544. +++++++++++++++++++++++++++
  1545.  
  1546. >From ari@world.std.com (Ari I Halberstadt)
  1547. Date: Thu, 20 Oct 1994 04:00:28 GMT
  1548. Organization: The World Public Access UNIX, Brookline, MA
  1549.  
  1550. In article <Jaeger-1910941228440001@slip-8-14.ots.utexas.edu>,
  1551. Brian Stern <Jaeger@fquest.com> wrote:
  1552. >In article <380uvh$lqm@nntp1.u.washington.edu>, jbeeghly@u.washington.edu
  1553. >(Jeff Beeghly) wrote:
  1554. >
  1555. ><  
  1556. ><  
  1557. >< >> Do I need to do a lot of watch dogging and not let any operations be
  1558. >< >> performed if the app goes beneath 0k of memory is free?
  1559. >...
  1560. >< Get my point?
  1561.  
  1562. Get ZoneRanger and a color monitor. This is the *coolest* free program
  1563. for figuring out what the heck your app is doing in its memory
  1564. partition. It should be on any archive site and plenty of CDs.
  1565. Also, get ProcessWatcher, another free and useful tool.
  1566.  
  1567. >Most of the sample code I've seen uses a size of about 40K as the time to
  1568. >post a low memory warning.  Since we're talking about 'Real World' apps
  1569. >you should know that ALL real world apps have a growZone procedure and use
  1570. >some mechanism for keeping a buffer of memory available.  Usually this
  1571. >done by a mechanism known as the rainy-day fund.  Briefly, at app startup
  1572. >you allocate a handle of, say, 40K.  That's your rainy day fund.  Each
  1573. >time through your main event loop ( or perhaps only on null events) you
  1574. >check the available memory.  If it's too low you post a warning alert. 
  1575. >Under some circumstances you release the rainy day handle.  Either from
  1576. >your growZone Proc or possibly in response to an explicit call from
  1577. >somewhere in your app.
  1578.  
  1579. I've abstracted and elaborated this. Each level in an app gets a
  1580. reserve memory. Then there's a memory cushion in addition. The app
  1581. sets the allocation level. The Toolbox level is the lowest, since the
  1582. TB can crash if it doesn't get memory. When I need to allocate memory,
  1583. I bump up the level, then restore it afterwards. For critical things,
  1584. like quitting and saving a file, I bump up the memory to a "critical"
  1585. level. Each level allows access to different memory reserves. The size
  1586. of the memory reserves for each level is set in a configuration
  1587. resource. The grow zone function runs a loop in which it frees up
  1588. reserves (depending on the current level) until enough bytes have been
  1589. freed. Memory warnings are issued depending on how much of the
  1590. reserves are depleted and how little memory is left. At each warning
  1591. level, the application can take different actions, e.g., at first just
  1592. an alert, then disabling functions like undo, then automatically
  1593. asking the user to close files, then automatically closing unmodified
  1594. files and saving modified files to temporary locations, and, finally,
  1595. terminating the application if all of the reserves are depleted and
  1596. there is very little memory left (e.g., less than 10K). I also have
  1597. code to automatically unload inactive segments, but it's not very
  1598. portable (works only with THINK C, not with Metrowerks).
  1599.  
  1600. >...
  1601. >< 1 Unconventional.  I'm not taliking about event-driven programming
  1602. >< conceps, but things like string types.  Who the hell even USES s for most operations because I always have
  1603. the length available without worrying about caching the result of
  1604. 'strlen'. The fact that there are a zillion 'Str...' shouldn't faze you;
  1605. they're just Pascal strings with different maximum sizes. I use 'Str15',
  1606. for example, all the time for quick calls to 'NumToString'.
  1607.  
  1608. > And linked lists... try doing
  1609. > a linked list on the Mac... I DARE YOU.
  1610.  
  1611. I have. Other posters have pointed out that handles on the Macintosh are
  1612. not the same as handles on Windows. There's no more difficulty in writing
  1613. linked list code on the Mac than there is in typing an extra '*'. (It's
  1614. when people start trying to optimize the double-dereferencing that they
  1615. get into trouble.)
  1616.  
  1617. > 3 Example code base is meeger.  There are several areas of Mac programming
  1618. > which need some indepth examples.  The app which I'm writing shouldn't
  1619. > have taken this long, but I got locked up on a couple topics.
  1620.  
  1621. This is an odd observation, given that you appear to have "real" internet
  1622. access. Perhaps you are unaware of the many 'ftp' archive sites. There is
  1623. also copious example code on the various CD ROMs produced by Apple.
  1624.  
  1625. > >        (new) Inside Macintosh: Memory - for references to
  1626. > >        questions about: MoreMasters, NewHandle, CompactMem,
  1627. > >        PurgeMem, FreeMem, etc.
  1628. >  
  1629. > Don't have it, but I have THINK Reference.
  1630.  
  1631. You absitively posolutely need to buy the relevant Inside Macintosh
  1632. volumes. They cost a lot of money. You need to buy them anyway.
  1633.  
  1634. -- 
  1635.  Views expressed here do not necessarily reflect the views of Novell.
  1636.  
  1637. ---------------------------
  1638.  
  1639. >From pwhull@crl.com (Peter Hull)
  1640. Subject: NewGWorld returns null pointer
  1641. Date: 20 Oct 1994 09:24:21 GMT
  1642. Organization: CRL Dialup Internet Access    (415) 705-6060  [Login:
  1643. guest]
  1644.  
  1645. Hello,
  1646.  
  1647. I have a problem related to using GWorlds-- NewGWorld returns null in the
  1648. GWorld pointer.  I am using TCL 1.1.3.  When the problem occurs, I already
  1649. have one document object open, identical to the one I am trying to create.
  1650. If I close the first document and then open a second one, everything is
  1651. cool.  But if I try to open a second document while the first is still open,
  1652. when my CGWorld object calls NewGWorld to create the offscreen world, it
  1653. gets this null pointer.  I am running the program in 4 megs of memory,
  1654. and the images are only 256x256 pixels.  (I'm using the Pico sample images
  1655. from 'develop' #10, from 'develop' CD #19.)
  1656.  
  1657. Does anybody have any idea why NewGWorld would return a null GWorld?  There's
  1658. nothing in Inside Macintosh that would suggest that NewGWorld might return
  1659. a null pointer except for the example code in NIM: "Imaging with QuickDraw",
  1660. chapter 6, which tests for a null pointer.  That is where I got the idea that
  1661. that might be the problem.  (Originally I thought the problem might be with
  1662. DrawPicture, because that's where the program froze.)
  1663.  
  1664. Any help would be appreciated...
  1665.  
  1666. Thanks in advance!
  1667.  
  1668. --
  1669. --
  1670. Peter Hull <pwhull@crl.com>
  1671.  
  1672. +++++++++++++++++++++++++++
  1673.  
  1674. >From pwhull@crl.com (Peter Hull)
  1675. Date: 20 Oct 1994 21:18:34 GMT
  1676. Organization: CRL Dialup Internet Access    (415) 705-6060  [Login:
  1677. guest]
  1678.  
  1679. Peter Hull (pwhull@crl.com) wrote:
  1680. : Hello,
  1681.  
  1682. : I have a problem related to using GWorlds-- NewGWorld returns null in the
  1683. : GWorld pointer.  I am using TCL 1.1.3.  When the problem occurs, I already
  1684. : have one document object open, identical to the one I am trying to create.
  1685. : If I close the first document and then open a second one, everything is
  1686. : cool.  But if I try to open a second document while the first is still
  1687. open,
  1688. : when my CGWorld object calls NewGWorld to create the offscreen world, it
  1689. : gets this null pointer.  I am running the program in 4 megs of memory,
  1690. : and the images are only 256x256 pixels.  (I'm using the Pico sample images
  1691. : from 'develop' #10, from 'develop' CD #19.)
  1692.  
  1693. : Does anybody have any idea why NewGWorld would return a null GWorld? 
  1694. There's
  1695. : nothing in Inside Macintosh that would suggest that NewGWorld might return
  1696. : a null pointer except for the example code in NIM: "Imaging with
  1697. QuickDraw",
  1698. : chapter 6, which tests for a null pointer.  That is where I got the idea
  1699. that
  1700. : that might be the problem.  (Originally I thought the problem might be with
  1701. : DrawPicture, because that's where the program froze.)
  1702.  
  1703. I now have discovered that the problem occurs also on the first document
  1704. object sometimes.  Why this is I still have no idea.  Here is the call,
  1705. straight from my source code:
  1706.  
  1707.     FailOSErr(anErr = NewGWorld(&itsWorld, depth,
  1708.                   &boundsRect, NULL, NULL, 0));
  1709.  
  1710. 'boundsRect' is { 0, 0, 256, 256 }, 'depth' is 16.
  1711.  
  1712. After the call, sometimes 'itsWorld' is NULL.
  1713.  
  1714. However, I have never had an error show up in 'anErr'.
  1715. Any ideas?
  1716.  
  1717. --
  1718. --
  1719. Peter Hull <pwhull@crl.com>
  1720.  
  1721. +++++++++++++++++++++++++++
  1722.  
  1723. >From Jaeger@fquest.com (Brian Stern)
  1724. Date: 23 Oct 1994 18:07:12 GMT
  1725. Organization: The University of Texas at Austin, Austin, Texas
  1726.  
  1727. In article <386mra$kqk@nntp.crl.com>, pwhull@crl.com (Peter Hull) wrote:
  1728.  
  1729. < Peter Hull (pwhull@crl.com) wrote:
  1730. < : Hello,
  1731. < : I have a problem related to using GWorlds-- NewGWorld returns null in the
  1732. < : GWorld pointer.  I am using TCL 1.1.3.  When the problem occurs, I
  1733. already
  1734. <         FailOSErr(anErr = NewGWorld(&itsWorld, depth,
  1735. <                   &boundsRect, NULL, NULL, 0));
  1736. < 'boundsRect' is { 0, 0, 256, 256 }, 'depth' is 16.
  1737. < After the call, sometimes 'itsWorld' is NULL.
  1738. < However, I have never had an error show up in 'anErr'.
  1739. < Any ideas?
  1740. < --
  1741. < --
  1742. < Peter Hull <pwhull@crl.com>
  1743.  
  1744. Actually this very question was posted a month or so back.  Are you
  1745. locking the object before making this call?  NewGWorld moves memory.  TCL
  1746. 1.1.3 objects are handles.  If itsWorld is an instance varible and the
  1747. object is unlocked then NewGWorld will succeed but &itsWorld won't point
  1748. to the object anymore.  Either lock the object, or use a local varible for
  1749. the first parameter to NewGWorld and  then set itsWorld from the local
  1750. variable.
  1751.  
  1752. Good luck,
  1753.  
  1754. -- 
  1755. Brian  Stern  :-{)}
  1756. Toolbox commando and Menu bard
  1757. Jaeger@fquest.com
  1758.  
  1759. +++++++++++++++++++++++++++
  1760.  
  1761. >From pwhull@crl.com (Peter Hull)
  1762. Date: 24 Oct 1994 10:16:33 GMT
  1763. Organization: CRL Dialup Internet Access    (415) 705-6060  [login:
  1764. guest]
  1765.  
  1766. Regarding the GWorld problem with NewGWorld returning a null pointer,
  1767. Brian Stern's solution was correct.  He suggested that the problem was
  1768. being caused by NewGWorld moving memory while the object that called
  1769. it was unlocked in the heap.  This caused the (handle-based) object to
  1770. not receive the pointer correctly.  Here is my implementation of the fix:
  1771.  
  1772. HLock ((Handle) this);
  1773.  
  1774. <NewGWorld call here>
  1775.  
  1776. HUnlock ((Handle) this);
  1777.  
  1778. Depressingly simple, isn't it?  Many thanks to Brian and also to
  1779. Francois Pottier who e-mailed me with the same solution.
  1780.  
  1781. Cheers,
  1782.  
  1783. Peter
  1784.  
  1785. --
  1786.  
  1787. Peter Hull
  1788. <pwhull@crl.com>
  1789.  
  1790. ---------------------------
  1791.  
  1792. >From mclow@san_marcos.csusm.edu (Marshall Clow)
  1793. Subject: Pathnames? I don't think so...
  1794. Date: Fri, 14 Oct 1994 17:36:29 -0700
  1795. Organization: Aladdin Systems
  1796.  
  1797. In article <272202942.8010432@chatter.chatter.com>,
  1798. Daaron_Dwyer@chatter.com wrote:
  1799.  
  1800. > Not to answer the question, but to advance it to a different level, when
  1801. you
  1802. > do a call to FindFolder (let's say to find the preferences folder on the
  1803. > startup volume) and you get a Folder ID, what is the most efficient way to
  1804. > convert it or utilize the information to be a path?
  1805. > Just another newbie,
  1806.  
  1807. OK. Here we go:
  1808.    On the mac, in general, you don't want to use pathnames. Users have
  1809. this distressing habit of moving files and renaming folders.
  1810.  
  1811. To open/rename/delete/etc a file:
  1812.    All the appropriate routines take a triplet:
  1813.       volume, directory ID, and file name.
  1814. In your example, you already have a volume refnum, and directory ID,
  1815. (from your call to FindFolder), and presumably you have the name.
  1816.    err = HOpen ( vrefNum, dirID, fName, fsRdWrPerm, &refNum );
  1817.  
  1818.  
  1819. To save the location of a file so you can find it later:
  1820.    Use the alias manager.
  1821.  
  1822. NewAlias (...);
  1823. later: ResolveAlias ( ... );
  1824.  
  1825. -- 
  1826. Marshall Clow
  1827. Aladdin Systems
  1828. mclow@san_marcos.csusm.edu
  1829.  
  1830.  
  1831. ---------------------------
  1832.  
  1833. >From bb@lightside.com (Bob Bradley)
  1834. Subject: Q: Creating Variable sized structures?
  1835. Date: Sun, 16 Oct 1994 09:26:42 -0800
  1836. Organization: SS Software Inc.
  1837.  
  1838. How do you create variable sized structures, similar to how DITL resources
  1839. are used by the Dialog Manager?
  1840.  
  1841. Do they just create a handle and tack on things as they go? If so, it
  1842. would seem like they'd need some sort of index or they'd have to parse the
  1843. list each time to access individual items.
  1844.  
  1845. I'm writing a View-like library for creating Windows/Dialogs and I'm
  1846. looking for a good way to create variable sized structures that define the
  1847. details of the View but, having a tough time with this part of it.
  1848.  
  1849. Any comments appreciated.
  1850.  
  1851. +++++++++++++++++++++++++++
  1852.  
  1853. >From Eric Kidd <emk@dartmouth.edu>
  1854. Date: 18 Oct 1994 03:00:39 GMT
  1855. Organization: Dartmouth College
  1856.  
  1857. Q: Creating Variable sized structures?
  1858.  
  1859. One easy way to do this is--if the variable part of the record is of
  1860. constant
  1861. size--is to define a struct like:
  1862.  
  1863. typedef struct
  1864. {
  1865.    // header info
  1866.     
  1867.    short index;
  1868.    element_type element[1];
  1869. } myType;
  1870.  
  1871. Reference data of this type with a handle and use the memory manager
  1872. (ResizeHandle? SizeHandle? I forget at the moment.) to resize it as you
  1873. need. You
  1874. could write a routine:
  1875.  
  1876.    ResizeMyType( myType** theData, short numSlots )
  1877.  
  1878. and call it as needed. Hope this helps. Any feedback appreciated.
  1879.  
  1880. +++++++++++++++++++++++++++
  1881.  
  1882. >From Jaeger@fquest.com (Brian Stern)
  1883. Date: 18 Oct 1994 06:52:05 GMT
  1884. Organization: The University of Texas at Austin, Austin, Texas
  1885.  
  1886. In article <bb-1610940926420001@user38.lightside.com>, bb@lightside.com
  1887. (Bob Bradley) wrote:
  1888.  
  1889. < How do you create variable sized structures, similar to how DITL resources
  1890. < are used by the Dialog Manager?
  1891. < Do they just create a handle and tack on things as they go? If so, it
  1892. < would seem like they'd need some sort of index or they'd have to parse the
  1893. < list each time to access individual items.
  1894. < I'm writing a View-like library for creating Windows/Dialogs and I'm
  1895. < looking for a good way to create variable sized structures that define the
  1896. < details of the View but, having a tough time with this part of it.
  1897. < Any comments appreciated.
  1898.  
  1899. Yes, variable-sized resources are built by allocating a handle and then
  1900. tacking things onto the end of it.  The routines like GetDItem, SetDItem,
  1901. and GetIndString walk down the resource each time to find the particular
  1902. item's data.  In general these data structures are small so that finding
  1903. the third or tenth item doesn't take very long.  Finding the hundreth or
  1904. thousandth item this way would be very slow.
  1905.  
  1906. Each of the items in these variable length data structures has a length
  1907. byte or short that is at a fixed offset from the beginning of each item
  1908. (often the offset is zero) to facilitate walking down the structure.  Also
  1909. the resource has an entry count in it, usually at the beginning.  Adding a
  1910. new item at the end is just a matter of using PtrAndHand and then updating
  1911. the item counter.  Modifying existing items or inserting items in the
  1912. middle is a matter of adjusting the size of the handle and blockmove to
  1913. make space in the middle, followed by blockmove to insert the new data.
  1914.  
  1915. My personal favorite is the Speech Manager 'dict' resource.  In this
  1916. perverse resource there is a header, followed by a variable length array
  1917. of variable length records.  Each of these last records consists of two
  1918. (or more) variable length records.  Sort of like an array of STR#
  1919. resources.
  1920.  
  1921. -- 
  1922. Brian  Stern  :-{)}
  1923. Toolbox commando and Menu bard
  1924. Jaeger@fquest.com
  1925.  
  1926. +++++++++++++++++++++++++++
  1927.  
  1928. >From larson@base.cs.ucla.edu (Christopher Larson)
  1929. Date: 18 Oct 1994 16:51:27 GMT
  1930. Organization: UCLA, Computer Science Department
  1931.  
  1932. In article <37vdon$gvt@dartvax.dartmouth.edu> Eric Kidd <emk@dartmouth.edu>
  1933. writes:
  1934. >Q: Creating Variable sized structures?
  1935. >
  1936. >One easy way to do this is--if the variable part of the record is of
  1937. >constant
  1938. >size--is to define a struct like:
  1939. >
  1940. >typedef struct
  1941. >{
  1942. >   // header info
  1943. >    
  1944. >   short index;
  1945. >   element_type element[1];
  1946. >} myType;
  1947.  
  1948. In THINK C (don't know about CW) it is legal to declare an array of
  1949. unspecified
  1950. size (e.g. "element_type element[];") which will not contribute to the size
  1951. of
  1952. the struct.:05:00 GMT
  1953. Organization: Dept. of Computer Science, Concordia University
  1954.  
  1955. In article <380ppq$nep@hearst.cac.psu.edu>, emb121@hearst.cac.psu.edu (Eric
  1956. Bennett) writes:
  1957. |> I have successfully used PBSetVInfo to software-lock a volume as
  1958. |> described in Inside Mac: Files on page 2-147, which deals with
  1959. |> PBSetVInfo (call PBGetVInfo, set bit 15 of the ioVAtrb field, and call
  1960. |> PBSetVInfo).  The only problem is that I cannot UNLOCK these volumes
  1961. |> using the same method (this time clearing bit 15)--I get the error
  1962. |> "volume locked" (error -43, I think). Yes, the volume is locked, but
  1963. |> shouldn't the command which can set the lock be able to unlock it? 
  1964. |> What toolbox call CAN I use to unlock a software-locked volume?
  1965. |> 
  1966. |> Thanks,
  1967. |> Ericb@psu.edu 
  1968.  
  1969.  
  1970.  
  1971. I will help you !
  1972. I have made a soft called DiskLocker that made what you want.
  1973. Before unlocking the disk with PBSetVInfo, you must update a global variable
  1974. used by the Finder. I do not remember its name and its structure but I will
  1975. check at home and I will reply to you again soon.
  1976.  
  1977.  
  1978. olivier lebra      olebra@aedi.insa-lyon.fr  or lebra@cs.concordia.ca 
  1979.  
  1980. +++++++++++++++++++++++++++
  1981.  
  1982. >From sbryan@maroon.tc.umn.edu (Steve Bryan)
  1983. Date: Fri, 21 Oct 1994 06:24:29 GMT
  1984. Organization: Sexton Software
  1985.  
  1986. > In article <380ppq$nep@hearst.cac.psu.edu>, emb121@hearst.cac.psu.edu
  1987. > (Eric Bennett) wrote:
  1988. >  Yes, the volume is locked, but
  1989. > > shouldn't the command which can set the lock be able to unlock it? 
  1990. > > What toolbox call CAN I use to unlock a software-locked volume?
  1991.  
  1992. I don't know if you already have the response but the trick is to update
  1993. the vcb queue elem before making the unlock toolbox call. You can get the
  1994. vcb queue elem either by "walking the vcb queue" and setting the
  1995. appropriate bit in place (I think it is one of the bits in the attribute
  1996. field) or make a couple of calls to PBGetVInfo and PBSetVInfo. This
  1997. strategy worked for a little control panel I wrote many years ago (ie the
  1998. source code is not handy). Good luck.
  1999.  
  2000. -- 
  2001. Steve Bryan                  InterNet: sbryan@maroon.tc.umn.edu
  2002. Sexton Software            CompuServe: 76545,527
  2003. Minneapolis, MN                   Fax: (612) 929-1799
  2004.  
  2005. +++++++++++++++++++++++++++
  2006.  
  2007. >From lebra@cs.concordia.ca (LEBRA olivier)
  2008. Date: 21 Oct 1994 19:08:39 GMT
  2009. Organization: Dept. of Computer Science, Concordia University
  2010.  
  2011. In article <sbryan-2110940024290001@dialup-3-184.gw.umn.edu>,
  2012. sbryan@maroon.tc.umn.edu (Steve Bryan) writes:
  2013. |> > In article <380ppq$nep@hearst.cac.psu.edu>, emb121@hearst.cac.psu.edu
  2014. |> > (Eric Bennett) wrote:
  2015. |> > 
  2016. |> >  Yes, the volume is locked, but
  2017. |> > > shouldn't the command which can set the lock be able to unlock it? 
  2018. |> > > What toolbox call CAN I use to unlock a software-locked volume?
  2019. |> > 
  2020. |> 
  2021. |> I don't know if you already have the response but the trick is to update
  2022. |> the vcb queue elem before making the unlock toolbox call. You can get the
  2023. |> vcb queue elem either by "walking the vcb queue" and setting the
  2024. |> appropriate bit in place (I think it is one of the bits in the attribute
  2025. |> field) or make a couple of calls to PBGetVInfo and PBSetVInfo. This
  2026. |> strategy worked for a little control panel I wrote many years ago (ie the
  2027. |> source code is not handy). Good luck.
  2028. |> 
  2029. |> -- 
  2030. |> Steve Bryan                  InterNet: sbryan@maroon.tc.umn.edu
  2031. |> Sexton Software            CompuServe: 76545,527
  2032. |> Minneapolis, MN                   Fax: (612) 929-1799
  2033.  
  2034.  
  2035. I think the simplest way to update the vcb queue is :
  2036. DefVCBPtr->vcbAtrb &= 0x7FFF;
  2037.  
  2038.  
  2039. -- 
  2040. *********************************************************************
  2041. *        olivier       * Until July 1996 : olebra@aedi.insa-lyon.fr *
  2042. *         lebra        * Until May 1995  : lebra@cs.concordia.ca    *
  2043. *********************************************************************
  2044. * 1950, Lincoln  App #1707  -  H3H 2N8  Montreal, Quebec  -  CANADA *
  2045. * Phone : (+1) 514-846 9781                                         *
  2046. *********************************************************************
  2047. *     "La simplicite est l'ultime forme de la sophistication."      *
  2048. *********************************************************************
  2049.  
  2050. +++++++++++++++++++++++++++
  2051.  
  2052. >From emb121@hearst.cac.psu.edu (Eric Bennett)
  2053. Date: 24 Oct 1994 16:18:11 GMT
  2054. Organization: Penn State University
  2055.  
  2056. In article <88387349253@jonathan.srcc.msu.su>
  2057. kluev@jonathan.srcc.msu.su (Kluev) writes:
  2058.  
  2059. > Try clear locked flag of vcbAtrb field of VCB describing volume.
  2060. > You can find VCB using GetVCBQHdr call and stepping via dLink
  2061. > field until you find the volume. This method, however, should
  2062. > be treated as modifying internal File Manager structures and
  2063. > should be avoided if possible.
  2064.  
  2065. I know--Inside Mac says DON'T PLAY WITH THE VCB--it is supposed to be
  2066. read only, not written to.  My question was, if I'm not supposed to
  2067. modify the VCB, how do I unlock the volume?  (Incidentally, when I
  2068. tried modifying the VCB, my machine locked up; however, since that's
  2069. the only suggestion I've gotten, I guess I'll try doing it again :).
  2070.  
  2071. -Ericb@psu.edu
  2072.  
  2073. ---------------------------
  2074.  
  2075. >From rang@winternet.com (Anton Rang)
  2076. Subject: Some string routines for the PowerPC
  2077. Date: 15 Oct 1994 21:29:50 GMT
  2078. Organization: Trillium Research, Inc.
  2079.  
  2080. Archive-name: ppc-string-utils.txt
  2081. Submitted-by: rang@winternet.com
  2082.  
  2083. This file implements some basic string routines for both C and Pascal
  2084. strings.  It's written in PowerPC assembly.  I did this mainly as a
  2085. learning experience; I was bored one day, and wanted to play with the
  2086. string instructions.
  2087.  
  2088. Routines implemented here are:
  2089.  
  2090.   strcpy and strcat -- both of these are about 30% faster than those
  2091.                provided by Apple or Metrowerks.
  2092.  
  2093.   pstrcpy and pstrcat -- very fast versions of the above for use with
  2094.              Pascal-style strings; much faster than those
  2095.              provided by Apple (PLstrcpy/PLstrcat).
  2096.  
  2097.   pstreq -- a fast equality test for Pascal-style strings.
  2098.  
  2099. If there's interest, I may develop and post more of these later.
  2100.  
  2101. I've appended a binhexed object library for those without an assembler.
  2102.  
  2103. An open question: Is there interest in developing a complete, or at
  2104. least subset, copyright-free, optimized, ANSI library for the PowerPC?
  2105. I see people complaining about Metrowerks' implementation, and neither
  2106. Metrowerks nor Apple has so far released a highly optimized library.
  2107. I'd rather see them concentrating on compiler technology, anyway.  If
  2108. there's enough interest, surely those of us on the net could compile a
  2109. reasonably complete library.  This would surely benefit all of the Mac
  2110. community.
  2111.  
  2112.   -- Anton
  2113.  
  2114. - -------- mylib.s
  2115. ;
  2116. ; Anton's library of handy string routines and such.
  2117. ;
  2118.  
  2119. ;
  2120. ; char *strcpy(char *, const char *)
  2121. ;
  2122. ; Copy a null-terminated string from one location to another; return the
  2123. first location.
  2124. ; This goes really fast if you use the POWER 'lscbx' instruction.  *sigh*
  2125. ;
  2126.  
  2127.         export  my_strcpy[DS]
  2128.         export  .my_strcpy[PR]
  2129.         
  2130.         toc
  2131.             tc  my_strcpy[TC], my_strcpy[DS]
  2132.         
  2133.         csect   my_strcpy[DS]
  2134.             dc.l    .my_strcpy[PR]
  2135.             dc.l    TOC[tc0]
  2136.             dc.l    0
  2137.         
  2138.         csect   .my_strcpy[PR]
  2139.  
  2140.         ; First, move R3 into R5, so we have a copy we can change.  Bias it
  2141. down by one byte.
  2142.         ; Bias R4 down too.
  2143.  
  2144.         subi    r5, r3, 1
  2145.         subi    r4, r4, 1
  2146.  
  2147.         ; Read a byte, store it, and compare it against zero.  Loop until we
  2148. find the zero.
  2149.         ; By issuing the compare before the store, we save one cycle in
  2150. branch resolution.
  2151.  
  2152. @0:     lbzu    r0, 1(r4)
  2153.         cmpwi   r0, 0
  2154.         stbu    r0, 1(r5)
  2155.         bne     @0
  2156.  
  2157.         ; All done.  Note that R3 has the return value already.
  2158.  
  2159.         blr
  2160.  
  2161. ;
  2162. ; void pstrcpy(unsigned char *, const unsigned char *)
  2163. ;
  2164. ; Copy a byte-counted string from one location to another.
  2165. ;
  2166.  
  2167.         export  pstrcpy[DS]
  2168.         export  .pstrcpy[PR]
  2169.         
  2170.         toc
  2171.             tc  pstrcpy[TC], pstrcpy[DS]
  2172.         
  2173.         csect   pstrcpy[DS]
  2174.             dc.l    .pstrcpy[PR]
  2175.             dc.l    TOC[tc0]
  2176.             dc.l    0
  2177.         
  2178.         csect   .pstrcpy[PR]
  2179.  
  2180.         ; Get the byte count, and add one to it to include the length byte.
  2181.  
  2182.         lbz     r5, 0(r4)
  2183.         addi    r5, r5, 1
  2184.  
  2185.         ; If the length is <= 32, we can complete the move in one pass.  We
  2186. assume that this
  2187.         ; is the most common case, and hence set the branch-predict bit here.
  2188.         ; (Why 32 bytes?  We have 8 non-volatile scratch registers, R5..R12,
  2189. to use.)
  2190.  
  2191. @0:     cmpwi   r5, 32
  2192.         ble+    @1
  2193.  
  2194.         ; OK...more than 32 bytes to move.  We'll move 28 bytes and then see
  2195. if we can finish.
  2196.         ; (Why 28 bytes?  We're holding the length in R5, so we only have 7
  2197. scratch registers.)
  2198.  
  2199.         subi    r5, r5, 28
  2200.  
  2201.         lswi    r6, r4, 28
  2202.         addi    r4, r4, 28
  2203.  
  2204.         stswi   r6, r3, 28
  2205.         addi    r3, r3, 28
  2206.  
  2207.         b       @0
  2208.  
  2209.         ; We complete the move here, mov    b       @0
  2210.  
  2211.         ; We complete the move here, moving between 1 and 32 bytes.
  2212.  
  2213. @1:     mtxer   r5
  2214.  
  2215.         lswx    r5, r0, r4
  2216.         stswx   r5, r0, r3
  2217.  
  2218.         blr
  2219.  
  2220. ;
  2221. ; char *strcat(char *, const char *)
  2222. ;
  2223. ; Concatenate a null-terminated string onto another; return the address of
  2224. the first string.
  2225. ;
  2226.  
  2227.         export  my_strcat[DS]
  2228.         export  .my_strcat[PR]
  2229.         
  2230.         toc
  2231.             tc  my_strcat[TC], my_strcat[DS]
  2232.         
  2233.         csect   my_strcat[DS]
  2234.             dc.l    .my_strcat[PR]
  2235.             dc.l    TOC[tc0]
  2236.             dc.l    0
  2237.         
  2238.         csect   .my_strcat[PR]
  2239.  
  2240.         ; First, move R3 into R5, so we have a copy we can change.  Bias it
  2241. down by one byte.
  2242.         ; Bias R4 down too.
  2243.  
  2244.         subi    r5, r3, 1
  2245.         subi    r4, r4, 1
  2246.  
  2247.         ; Walk down the first string to its end.
  2248.  
  2249. @0:     lbzu    r0, 1(r5)
  2250.         cmpwi   r0, 0
  2251.         bne     @0
  2252.  
  2253.         ; R5 is now one byte past the end of the string.  Go backwards to
  2254. bytes, so that
  2255.         ; it points just before the end of the string.
  2256.         
  2257.         subi    r5, r5, 2
  2258.  
  2259.         ; Read a byte, store it, and compare it against zero.  Loop until we
  2260. find the zero.
  2261.         ; By issuing the compare before the store, we save one cycle in
  2262. branch resolution.
  2263.  
  2264. @1:     lbzu    r0, 1(r4)
  2265.         cmpwi   r0, 0
  2266.         stbu    r0, 1(r5)
  2267.         bne     @1
  2268.  
  2269.         ; All done.  Note that R3 has the return value already.
  2270.  
  2271.         blr
  2272.  
  2273. ;
  2274. ; void pstrcat(unsigned char *, const unsigned char *)
  2275. ;
  2276. ; Concatenate a byte-counted string onto another.  This doesn't do any error
  2277. checking.
  2278. ;
  2279.  
  2280.         export  pstrcat[DS]
  2281.         export  .pstrcat[PR]
  2282.  
  2283.         toc
  2284.             tc  pstrcat[TC], pstrcat[DS]
  2285.  
  2286.         csect   pstrcat[DS]
  2287.             dc.l    .pstrcat[PR]
  2288.             dc.l    TOC[tc0]
  2289.             dc.l    0
  2290.  
  2291.         csect   .pstrcat[PR]
  2292.  
  2293.         ; Get the byte count of both strings.
  2294.  
  2295.         lbz     r6, 0(r3)
  2296.         lbz     r5, 0(r4)
  2297.  
  2298.         ; Note that lswx/stswx are defined to do nothing if the length (in
  2299. XER) is zero.
  2300.         ; If they weren't, we would want the following two lines, to check
  2301. that the
  2302.         ; concatenation is actually doing something.
  2303.  
  2304.         ; cmpwi r5, 0
  2305.         ; beqlr
  2306.  
  2307.         ; Add them together to get the new length; store it.
  2308.  
  2309.         add     r7, r6, r5
  2310.         stb     r7, 0(r3)
  2311.  
  2312.         ; Move destination address past old data (length + 1 bytes).
  2313.         ; Move source address past its length too (1 byte).
  2314.         
  2315.         addi    r3, r3, 1
  2316.         addi    r4, r4, 1
  2317.         add     r3, r3, r6
  2318.  
  2319.         ; If the length is <= 32, we can complete the move in one pass.  We
  2320. assume that this
  2321.         ; is the most common case, and hence set the branch-predict bit here.
  2322.         ; (Why 32 bytes?  We have 8 non-volatile scratch registers, R5..R12,
  2323. to use.)
  2324.  
  2325. @0:     cmpwi   r5, 32
  2326.         ble+    @1
  2327.  
  2328.         ; OK...more than 32 bytes to move.  We'll move 28 bytes and then see
  2329. if we can finish.
  2330.         ; (Why 28 bytes?  We're holding the length in R5, so we only have 7
  2331. scratch registers.)
  2332.  
  2333.         subi    r5, r5, 28
  2334.  
  2335.         lswi    r6, r4, 28
  2336.         addi    r4, r4, 28
  2337.  
  2338.         stswi   r6, r3, 28
  2339.         addi    r3, r3, 28
  2340.  
  2341.         b       @0
  2342.  
  2343.         ; We complete the move here, moving between 1 and 32 bytes.
  2344.  
  2345. @1:     mtxer   r5
  2346.  
  2347.         lswx    r5, r0, r4
  2348.         stswx   r5, r0, r3
  2349.  
  2350.         blr
  2351.  
  2352. ;
  2353. ; void pstrcatchr(unsigned char *dest, unsigned char src)
  2354. ;
  2355. ; Concatenate a single character onto a byte-counted string.
  2356. ;
  2357.  
  2358.         export  pstrcatchr[DS]
  2359.         export  .pstrcatchr[PR]
  2360.  
  2361.         toc
  2362.             tc  pstrcatchr[TC], pstrcatchr[DS]
  2363.  
  2364.         csect   pstrcatchr[DS]
  2365.             dc.l    .pstrcatchr[PR]
  2366.             dc.l    TOC[tc0]
  2367.             dc.l    0
  2368.  
  2369.         csect   .pstrcatchr[PR]
  2370.  
  2371.         ; Get the byte count of the string; add one to it and store it back.
  2372.  
  2373.         lbz     r5, 0(r3)
  2374.         addi    r5, r5, 1
  2375.         stb     r5, 0(r3)
  2376.         
  2377.         ; Store the character we want to concatenate at the end of the
  2378. string, and return.
  2379.  
  2380.         stbx    r4, r3, r5
  2381.         blr
  2382.  
  2383. ;
  2384. ; Boolean pstreq(unsigned char *s1, unsigned char *s2)
  2385. ;
  2386. ; Compare two byte-counted strings for equality; return true (1) if they're
  2387. equal.
  2388. ;
  2389.  
  2390.         export  pstreq[DS]
  2391.         export  .pstreq[PR]
  2392.  
  2393.         toc
  2394.             tc  pstreq[TC], pstreq[DS]
  2395.  
  2396.         csect   pstreq[DS]
  2397.             dc.l    .pstreq[PR]
  2398.             dc.l    TOC[tc0]
  2399.             dc.l    0
  2400.  
  2401.         csect   .pstreq[PR]
  2402.  
  2403.         ; First, get the byte count of both strings.
  2404.  
  2405.         lbz     r5, 0(r3)
  2406.         lbz     r6, 0(r4)
  2407.  
  2408.         ; If the byte counts aren't equal, fail immediately.
  2409.  
  2410.         cmpw    r5, r6
  2411.         bne     @fail
  2412.  
  2413.         ; OK, we have two strings of matching length.  Increment the
  2414. addresses to point to
  2415.         ; the actual text of the strings.
  2416.         
  2417.         addi    r3, r3, 1
  2418.         addi    r4, r4, 1
  2419.  
  2420.         ; If the length is <= 16, we can complete the comparison in one pass. 
  2421. We assume
  2422.         ; that this is the most common case, and hence set the branch-predict
  2423. bit here.
  2424.         ; (Why 16 bytes?  We have 8 non-volatile scratch registers, R5..R12,
  2425. to use.)
  2426.  
  2427. @0:     cmpwi   r5, 16
  2428.         ble+    @1
  2429.  
  2430.         ; OK...more than 16 bytes to compare.  We'll compare 12 bytes and
  2431. then see if we can
  2432.         ; finish.  (Why 12 bytes?  The length is in R5, so we only have 7
  2433. scratch registers,
  2434.         ; and we can only use whole registers for the string-load
  2435. instructions.)
  2436.  
  2437.         lswi    r6, r3, 12
  2438.         lswi    r9, r4, 12
  2439.  
  2440.         addi    r3, r3, 12
  2441.         addi    r4, r4, 12
  2442.         subi    r5, r5, 12
  2443.  
  2444.         ; Compare each of the register pairs R6/R9, R7/R10, R8/R11.  If any
  2445. differs, exit.
  2446.  
  2447.         cmp     0, 0, r6, r9
  2448.         cmp     1, 0, r7, r10
  2449.         cmp     2, 0, r8, r11
  2450.  
  2451.         bne     0, @fail
  2452.         bne     1, @fail
  2453.         bne     2, @fail
  2454.  
  2455.         b       @0
  2456.  
  2457.         ; We complete the comparison here, comparing between 1 and 16 bytes.
  2458.         ; If R5 is zero, we succeed immediately.
  2459.  
  2460. @1:     cmpwi   r5, 0
  2461.         beq     @succ
  2462.  
  2463.         ; Load the strings into R5..R8 and R9..R12.  Save R5 first.
  2464.  
  2465.         mr      r0, r5
  2466.         mtxer   r5
  2467.  
  2468.         lswx    r5, r0, r3
  2469.         lswx    r9, r0, r4
  2470.  
  2471.         ; Compare R5 against R9; if they differ, fail.
  2472.         ; If they're the same, and R0 is <= 4, succeed.
  2473.  
  2474.         cmp     0, 0, r5, r9
  2475.         cmpi    1, 0, r0, 4
  2476.         
  2477.         bne     0, @fail
  2478.         ble     1, @succ
  2479.  
  2480.         ; Compare R6 against R10; fail if different.  Succeed if R0 <= 8.
  2481.  
  2482.         cmp     0, 0, r6, r10
  2483.         cmpi    1, 0, r0, 8
  2484.         
  2485.         bne     0, @fail
  2486.         ble     1, @succ
  2487.  
  2488.         ; Compare R7 against R11; fail if different.  Succeed if R0 <= 12.
  2489.  
  2490.         cmp     0, 0, r7, r11
  2491.         cmpi    1, 0, r0, 12
  2492.         
  2493.         bne     0, @fail
  2494.         ble     1, @succ
  2495.  
  2496.         ; compare R8 against R12; fail if different, succeed if same.
  2497.  
  2498.         cmpw    r7, r11
  2499.         bne     @fail
  2500.  
  2501.         ; Success!
  2502.  
  2503. @succ:  li      r3, 1
  2504.         blr
  2505.  
  2506.         ; Failure
  2507.  
  2508. @fail:  li      r3, 0
  2509.         blr
  2510.  
  2511. - ----- mylib.s.o.hqx
  2512.  
  2513. --
  2514. Anton Rang (rang@winternet.com)
  2515.  
  2516. ---------------------------
  2517.  
  2518. >From blob@apple.com (Brian Bechtel)
  2519. Subject: Tech Notes on the World Wide Web, and History Is Made
  2520. Date: 19 Oct 1994 16:49:23 -0700
  2521. Organization: Apple Computer, Inc., Cupertino, California
  2522.  
  2523. New excitement on the digital traffic jam.  
  2524.  
  2525. Apple has now put all the tech notes (including the four new technotes
  2526. from the November developer CD which is _just_ going into the mail to
  2527. our developers right now as I type) on the Web.  Use Mosaic. Use MacWeb.
  2528. Use NetScape.  Explore.
  2529.  
  2530.  http://www.info.apple.com/dev/technotes/Main.html
  2531.  
  2532. The new tech notes include Jim Luther's "FL 37 Permission to do
  2533. What?!!?" (file permissions), Nitin Ganatra's "PS 02 Background-Only
  2534. Applications" (a revision of how to write faceless background
  2535. applications), Brian Bechtel's "OS 06 Control Strip Modules" (docs for
  2536. writing Control Strip modules, revised and corrected), and...
  2537.  
  2538.   Errata for Inside Macintosh:Networking
  2539.  
  2540. Yeah. That's right.  Rich Kubota and Scott Kuechle put together an
  2541. actual list of known errors in Inside Macintosh:Networking.  We have more
  2542. errata sheets under review, too.  When they get reviewed, we'll put them
  2543. up there as well.
  2544.  
  2545. For some help on getting started programming the Mac (and a desperate
  2546. plea for some feedback on said help), look at
  2547.  
  2548.  http://www.info.apple.com/dev/default.html
  2549.  
  2550. If you find this stuff useful, please let us know.  Thanks to Michelle
  2551. Wyner, ex-intern, and Mark Cookson for doing all the real work.
  2552.  
  2553. --Brian Bechtel     blob@apple.com     "My opinion, not Apple's"
  2554.  
  2555. If you don't know all these buzzwords, go read a different newsgroup
  2556. until you do.  Don't ask me; hell, I made up half of them myself.
  2557.  
  2558. ---------------------------
  2559.  
  2560. End of C.S.M.P. Digest
  2561. **********************
  2562.  
  2563.  
  2564. ---------------------------------------------------------------------
  2565.  
  2566. NOTE:  The following Macintosh file(s) are enclosed with this
  2567. message, in BinHex format.  If your mail system does not convert
  2568. BinHex files automatically, you will need to transfer the message to
  2569. a Mac and run the BinHex application to decode it.
  2570.  
  2571. Filename: mylib.s.o    Size:  1688 bytes
  2572.  
  2573. ---------------------------------------------------------------------
  2574.  
  2575. (This file must be converted with BinHex 4.0)
  2576.  
  2577.  
  2578.